|
1 2 3 4 |
$("a[href='#top']").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); |
|
1 2 3 4 |
$("a[href='#top']").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); |
|
1 2 3 4 5 |
<div class="button-block"> <button class="button">Прокрутить вниз</button> </div> <section class="section"></section> <footer class="footer" id="footer"></footer> |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function scrollTo(element) { window.scroll({ left: 0, top: element.offsetTop, behavior: 'smooth' }) } var button = document.querySelector('.button'); var footer = document.querySelector('#footer'); button.addEventListener('click', () => { scrollTo(footer); }) |
|
1 2 3 4 5 6 7 8 |
<div class="box"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <button class="prev">Назад</button> <button class="next">Вперёд</button> </div> |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$(document).ready(function () { $('.next').on('click', function () { if ($('div.active').index() == -1) { $('.box div:first-child').addClass('active'); } else { $('div.active').next('div').addClass('active'); $('div.active').prev('div').removeClass('active'); } }); $('.prev').on('click', function () { if ($('div.active').index() == -1) { /* без действий */ } else { $('div.active').prev('div').addClass('active'); $('div.active').next('div').removeClass('active'); } }); }); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body {font-family: Arial;} /* Style the tab */ .tab { overflow: hidden; border: 1px solid #ccc; background-color: #f1f1f1; } /* Style the buttons inside the tab */ .tab button { background-color: inherit; float: left; border: none; outline: none; cursor: pointer; padding: 14px 16px; transition: 0.3s; font-size: 17px; } /* Change background color of buttons on hover */ .tab button:hover { background-color: #ddd; } /* Create an active/current tablink class */ .tab button.active { background-color: #ccc; } /* Style the tab content */ .tabcontent { display: none; padding: 6px 12px; -webkit-animation: fadeEffect 1s; animation: fadeEffect 1s; } /* Fade in tabs */ @-webkit-keyframes fadeEffect { from {opacity: 0;} to {opacity: 1;} } @keyframes fadeEffect { from {opacity: 0;} to {opacity: 1;} } </style> </head> <body> <h3>Fade in Tabs</h3> <div class="tab"> <button class="tablinks" onclick="openCity(event, 'London')">London</button> <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button> <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button> </div> <div id="London" class="tabcontent"> <h3>London</h3> <p>London is the capital city of England.</p> </div> <div id="Paris" class="tabcontent"> <h3>Paris</h3> <p>Paris is the capital of France.</p> </div> <div id="Tokyo" class="tabcontent"> <h3>Tokyo</h3> <p>Tokyo is the capital of Japan.</p> </div> <script> function openCity(evt, cityName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tablinks = document.getElementsByClassName("tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); } document.getElementById(cityName).style.display = "block"; evt.currentTarget.className += " active"; } </script> </body> </html> |
|
1 2 3 4 5 6 7 8 9 10 11 |
$.ajax({ type: 'get', url: 'https://old.bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date='+output+'&json', dataType: 'json', data: [], success: function(data) { //console.log(data); $('.pocent .usd').text(data[27].rate); } }); }); |
|
1 2 3 4 5 6 7 |
var d = new Date(); var month = d.getMonth()+1; var day = d.getDate(); var output = d.getFullYear()+ ((''+month).length<2 ? '0' : '') + month + ((''+day).length<2 ? '0' : '') + day; //console.log(output); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
var count = 0; $(function() { updateCount(); $('input[type=checkbox]').change(function() { updateCount(this.checked ? 1 : -1); }); $('#invert').click(function(e) { e = $('input[type=checkbox]'); e.each(function(i, el) { el.checked = !el.checked; }); updateCount(e.length - count - count); }); }); function updateCount(a) { count = a ? count + a : $('input[type=checkbox]:checked').length; $('#count').text(count); } |
https://ru.stackoverflow.com/questions/29719/%D0%9F%D0%BE%D0%B4%D1%81%D1%87%D0%B5%D1%82-%D0%BA%D0%BE%D0%BB%D0%B8%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%B0-%D1%87%D0%B5%D0%BA%D0%B1%D0%BE%D0%BA%D1%81%D0%BE%D0%B2-%D0%BD%D0%B0-jquery
|
1 2 3 4 5 6 7 8 9 |
jQuery(function($){ $(document).mouseup(function (e){ // событие клика по веб-документу var div = $("#popup"); // тут указываем ID элемента if (!div.is(e.target) // если клик был не по нашему блоку && div.has(e.target).length === 0) { // и не по его дочерним элементам div.hide(); // скрываем его } }); }); |
jQuery: Закрытие элемента по клику за пределами его области (вне элемента)
|
1 2 3 4 5 6 7 8 9 |
$(function() { $('.select-list ul li').hover(function(){ var id = $(this).attr('id'); $('.select-list ul li').removeClass('active'); $(this).addClass('active'); $('.circle ul li').removeClass('active'); $('[data-pic="'+id+'"]').addClass('active'); }); }); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
.bl-1 .circle ul li.active(data-pic="image-1") img(src="/img/foto-list-1.jpg") li(data-pic="image-2") img(src="/img/foto-list-2.jpg") li(data-pic="image-3") img(src="/img/foto-list-3.jpg") li(data-pic="image-4") img(src="/img/foto-list-4.jpg") li(data-pic="image-5") img(src="/img/foto-list-5.jpg") li(data-pic="image-6") img(src="/img/foto-list-6.jpg") li(data-pic="image-7") img(src="/img/foto-list-7.jpg") li(data-pic="image-8") img(src="/img/foto-list-8.jpg") li(data-pic="image-9") img(src="/img/foto-list-9.jpg") li(data-pic="image-10") img(src="/img/foto-list-10.jpg") |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
.bl-2 .select-list ul li.active(id="image-1") Мягкую мебель, кровати li(id="image-2") Шкафы, стулья, столы li(id="image-3") Бытовую технику li(id="image-4") Спортивный инвентарь, велосипеды li(id="image-5") Садовые инструменты, стройматериалы li(id="image-6") Автомобильную резину, шины li(id="image-7") Личные домашние вещи li(id="image-8") Туристическое снаряжение li(id="image-9") Сумки, чемоданы li(id="image-10") Архивы, документы |
|
1 2 3 4 5 6 7 8 9 10 |
$(function() { $('.desktop-menu li a').mouseover(function(e){ e.preventDefault(); var deg = $('.cube').attr('style').match(/\d+/); if (deg[0] >= 50) { var res = +deg[0] + 90; $('.cube').css('transform', 'rotateY('+ res + 'deg)'); }; }); }); |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<nav> <ul> <li> <a href="#">Меню 1</a></li> <li> <a href="#">Меню 2</a></li> <li> <a href="#">Меню 3</a></li> <li> <a href="#">Меню 4</a></li> <li> <a href="#">Меню 5</a></li> <li> <a href="#">Меню 6</a></li> </ul> </nav> <div class="content"> <div class="cube" data-rotate="50"> <div class="back side"></div> <div class="left side"></div> <div class="right side"></div> <div class="top side"></div> <div class="bottom side"></div> <div class="front side"></div> </div> </div> |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<nav> <ul> <li> <a href="#">Меню 1</a></li> <li> <a href="#">Меню 2</a></li> <li> <a href="#">Меню 3</a></li> <li> <a href="#">Меню 4</a></li> <li> <a href="#">Меню 5</a></li> <li> <a href="#">Меню 6</a></li> </ul> </nav> <div class="content"> <div class="cube" data-rotate="0"> <div class="back side"></div> <div class="left side"></div> <div class="right side"></div> <div class="top side"></div> <div class="bottom side"></div> <div class="front side"></div> </div> </div> |