<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0">

<channel>

<title>Блог Чуденкова Алексея, заметки с тегом: jquery</title>
<link>https://blog.chudenkov.ru/tags/jquery/</link>
<description></description>
<generator>E2 (v3365; Aegea)</generator>

<item>
<title>jQuery: иконка показать пароль в поле при вводе</title>
<guid isPermaLink="false">78</guid>
<link>https://blog.chudenkov.ru/</link>
<comments>https://blog.chudenkov.ru/</comments>
<description>
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$(this).toggleClass(&amp;quot;help-eye help-eye-off&amp;quot;);
  var input = $($(this).attr(&amp;quot;toggle&amp;quot;));
  if (input.attr(&amp;quot;type&amp;quot;) == &amp;quot;password&amp;quot;) {
    input.attr(&amp;quot;type&amp;quot;, &amp;quot;text&amp;quot;);
  } else {
    input.attr(&amp;quot;type&amp;quot;, &amp;quot;password&amp;quot;);
  }
});&lt;/code&gt;&lt;/pre&gt;</description>
<pubDate>Thu, 12 Mar 2020 17:27:24 +0300</pubDate>
</item>

<item>
<title>jQuery: запретить вводить пробелы в E-Mail</title>
<guid isPermaLink="false">75</guid>
<link>https://blog.chudenkov.ru/all/jquery-zapretit-vvodit-probely-v-e-mail/</link>
<comments>https://blog.chudenkov.ru/all/jquery-zapretit-vvodit-probely-v-e-mail/</comments>
<description>
&lt;p&gt;Защита от дурака, который может скопировать и вставить почту с пробелами или хуже того ещё и написать её с пробелами.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$(&amp;quot;#input_Id&amp;quot;).change(function()
     $(this).val($(this).val().replace(/ +/g, ''))
});&lt;/code&gt;&lt;/pre&gt;</description>
<pubDate>Mon, 10 Feb 2020 14:05:01 +0300</pubDate>
</item>

<item>
<title>Shopify: add quantity button to cart</title>
<guid isPermaLink="false">71</guid>
<link>https://blog.chudenkov.ru/all/shopify-add-quantity-button-to-cart/</link>
<comments>https://blog.chudenkov.ru/all/shopify-add-quantity-button-to-cart/</comments>
<description>
&lt;p&gt;Добавить в cart-template.liquid&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;&amp;lt;input type='button' value='-' class='qtyminus' field='updates_{{ item.id }}' /&amp;gt;
&amp;lt;input type=&amp;quot;number&amp;quot; name=&amp;quot;updates[]&amp;quot; id=&amp;quot;updates_{{ item.id }}&amp;quot; class=&amp;quot;quantity&amp;quot; value=&amp;quot;{{ item.quantity }}&amp;quot; /&amp;gt;
&amp;lt;input type='button' value='+' class='qtyplus' field='updates_{{ item.id }}' /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Добавить в Assets cart.js и его содержание:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;jQuery(document).ready(function(){
    $('.qtyplus').click(function(e){
        e.preventDefault();
        fieldName = $(this).attr('field');
        var currentVal = parseInt($('input[id='+fieldName+']').val());
        if (!isNaN(currentVal)) {
            $('input[id='+fieldName+']').val(currentVal + 1);
        } else {
            $('input[id='+fieldName+']').val(0);
        }
    });
    $(&amp;quot;.qtyminus&amp;quot;).click(function(e) {
        e.preventDefault();
        fieldName = $(this).attr('field');
        var currentVal = parseInt($('input[id='+fieldName+']').val());
        if (!isNaN(currentVal) &amp;amp;&amp;amp; currentVal &amp;gt; 0) {
            $('input[id='+fieldName+']').val(currentVal - 1);
        } else {
            $('input[id='+fieldName+']').val(0);
        }
    });
});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Не забыть подключить JS с условием если вы находитесь на странице корзины, чтобы не перегружать сайт лишними скриптами.&lt;/p&gt;
</description>
<pubDate>Sat, 01 Feb 2020 13:35:31 +0300</pubDate>
</item>

<item>
<title>jQuery: readmore.js настройки</title>
<guid isPermaLink="false">67</guid>
<link>https://blog.chudenkov.ru/all/jquery-readmore-js-nastroyki/</link>
<comments>https://blog.chudenkov.ru/all/jquery-readmore-js-nastroyki/</comments>
<description>
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$('.content').readmore({
    speed: 435,
    maxHeight: 100,
    moreLink: '&amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;Подробнее&amp;lt;/a&amp;gt;',
    lessLink: '&amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;Скрыть&amp;lt;/a&amp;gt;',
    afterToggle: function(trigger, element, more) {
        if(more) {
            $(&amp;quot;.content span&amp;quot;).css(&amp;quot;background&amp;quot;, &amp;quot;none&amp;quot;);
        }
        if(! more) {
            $(&amp;quot;.content span&amp;quot;).css(&amp;quot;background&amp;quot;, &amp;quot;linear-gradient(0deg, #f3f3f3, transparent)&amp;quot;);
            $('html, body').animate({
                scrollTop: element.offset().top
            },{
                duration: 100
            });
        }
    }
});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Настройки readmore.js по-русски:&lt;/p&gt;
&lt;ol start="1"&gt;
&lt;li&gt;Speed — скорость разворачивания/сворачивания в милесекундах. Оптимально 500.&lt;/li&gt;
&lt;li&gt;maxHeight — высота отображаемого блока в пикселях.&lt;/li&gt;
&lt;li&gt;moreLink — название ссылки «подробнее».&lt;/li&gt;
&lt;li&gt;lessLink — название ссылки «спрятать».&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Далее мне необходимо сделать так, чтобы поверх текста был градиент, который не обрубал текст на указанных пикселях в maxHeight, а плавно сходил на «нет». Для этого я сделал span внутри элемента и добавил в него стили:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;.content span{ 
    background: linear-gradient(0deg, #f3f3f3, transparent);
    position: absolute;
    display: block;
    width: 100%;
    height: 100%;
    z-index: 10000;
  }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Соответственно при нажатии стили так и остаются, поэтому необходимо удалять фон при нажатии на кнопку «Подробнее». И для этого я написал условие:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;if(more) {
            $(&amp;quot;.content span&amp;quot;).css(&amp;quot;background&amp;quot;, &amp;quot;none&amp;quot;);
        }&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Но возникла ещё одна загвоздка, когда нажимаем кнопку «Скрыть», то фон не возвращался, поэтому было написано следующее условие:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;if(! more) {
            $(&amp;quot;.content span&amp;quot;).css(&amp;quot;background&amp;quot;, &amp;quot;linear-gradient(0deg, #f3f3f3, transparent)&amp;quot;);
            $('html, body').animate({
                scrollTop: element.offset().top
            },{
                duration: 100
            });&lt;/code&gt;&lt;/pre&gt;</description>
<pubDate>Sat, 16 Nov 2019 19:41:42 +0300</pubDate>
</item>

<item>
<title>JS: Плавный скролл по якорям на jQuery</title>
<guid isPermaLink="false">36</guid>
<link>https://blog.chudenkov.ru/all/plavny-skroll-po-yakoryam-na-jquery/</link>
<comments>https://blog.chudenkov.ru/all/plavny-skroll-po-yakoryam-na-jquery/</comments>
<description>
&lt;ol start="1"&gt;
&lt;li&gt;Создаем блок с идентификатором, в котором есть ссылка на якорь.&lt;/li&gt;
&lt;li&gt;Добавим скрипт, например, для блока с идентификатором menu:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$(document).ready(function(){
	$(&amp;quot;#menu&amp;quot;).on(&amp;quot;click&amp;quot;,&amp;quot;a&amp;quot;, function (event) {
		event.preventDefault(); //опустошим стандартную обработку
		var id  = $(this).attr('href'), //заберем айдишник блока с параметром URL
			top = $(id).offset().top; //определим высоту от начала страницы до якоря
	$('body,html').animate({scrollTop: top}, 1000); //сделаем прокрутку за 1 с
	});
});&lt;/code&gt;&lt;/pre&gt;&lt;ol start="3"&gt;
&lt;li&gt;Ф5, жмём кнопочки, любуемся.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Альтернативный вариант без использования идентификатора menu:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$(function(){$(&amp;quot;a[href*=#]:not([href=#])&amp;quot;).click(function(){if(location.pathname.replace(/^\//,&amp;quot;&amp;quot;)==this.pathname.replace(/^\//,&amp;quot;&amp;quot;)&amp;amp;&amp;amp;location.hostname==this.hostname){var t=$(this.hash);if(t=t.length?t:$(&amp;quot;[name=&amp;quot;+this.hash.slice(1)+&amp;quot;]&amp;quot;),t.length)return $(&amp;quot;html,body&amp;quot;).animate({scrollTop:t.offset().top},1000),!1}})});&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ещё один вариант без использования jQuery:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;var linkNav = document.querySelectorAll('[href^=&amp;quot;#&amp;quot;]'), //выбираем все ссылки к якорю на странице
    V = 1;  // скорость, может иметь дробное значение через точку (чем меньше значение - тем больше скорость)
for (var i = 0; i &amp;lt; linkNav.length; i++) {
    linkNav[i].addEventListener('click', function(e) { //по клику на ссылку
        e.preventDefault(); //отменяем стандартное поведение
        var w = window.pageYOffset,  // производим прокрутка прокрутка
            hash = this.href.replace(/[^#]*(.*)/, '$1');  // к id элемента, к которому нужно перейти
        t = document.querySelector(hash).getBoundingClientRect().top,  // отступ от окна браузера до id
            start = null;
        requestAnimationFrame(step);  // подробнее про функцию анимации [developer.mozilla.org]
        function step(time) {
            if (start === null) start = time;
            var progress = time - start,
                r = (t &amp;lt; 0 ? Math.max(w - progress/V, w + t) : Math.min(w + progress/V, w + t));
            window.scrollTo(0,r);
            if (r != w + t) {
                requestAnimationFrame(step)
            } else {
                location.hash = hash  // URL с хэшем
            }
        }
    }, false);
}&lt;/code&gt;&lt;/pre&gt;</description>
<pubDate>Sun, 06 May 2018 01:00:25 +0300</pubDate>
</item>

<item>
<title>Owl Carousel плавный скроллинг</title>
<guid isPermaLink="false">11</guid>
<link>https://blog.chudenkov.ru/all/owl-carousel-plavny-skrolling/</link>
<comments>https://blog.chudenkov.ru/all/owl-carousel-plavny-skrolling/</comments>
<description>
&lt;p&gt;По умолчанию в owl carousel слайдер как-то грубо перелистывает картинки.&lt;br /&gt;
Лечится так:&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code&gt;$('.class').owlCarousel({
            smartSpeed:1000
        })&lt;/code&gt;&lt;/pre&gt;</description>
<pubDate>Tue, 20 Mar 2018 00:27:10 +0300</pubDate>
</item>


</channel>
</rss>