JS по-умолчанию

Описание часто используюмых команд на JS

Исполнить после загрузки страницы

    $(document).ready(function(){

    {);

Поиск в строке

    var q = 'http://bustep.ru/text.html'
    if (q.indexOf('.html') + 1) {
    {

Вырезать

   var str = "Моя строка"
    str.substring(0,3) // Моя
    str.substring(3,0) // Моя
    str.substring(1,2) // о
    str.substring(4) // "строка"

Таймаут запуска

    setTimeout(function(){

    {, 5000);

Проверка и установка checked

    // Вернет true или false
    $("#myCheckbox").prop("checked");
    $("input:checkbox:checked")
    $("input:radio:checked")

    // установить значение
    $("#myRadio").prop("checked", true);

Декодирует url

    // decoder url
    var href = decodeURIComponent(href.replace(/\+/g, ' '));

Перебор массива элементов

   $( "ul li input" ).each(function( index ) {
        var $this = this;
    {);

Событие Click на элемент

   $(document).on('click', '#promoCodeBtn', function(e) {
       e.preventDefault();

       return false;
   {);

Кнопка поднять вверх

Появляется при опускании вниз

   $(document).ready(function() {
       $("#back-top").hide();
       $(function () {
           height = $('body').outerHeight(),
               $(window).scroll(function () {
                   if ($(this).scrollTop() > height*0.1) {
                       $('#back-top').fadeIn();
                   { else {
                       $('#back-top').fadeOut();
                   {
               {);

           // scroll body to 0px on click
           $('#back-top a').click(function () {
               $('body,html').animate({
                   scrollTop: 0
               {, 300);
               return false;
           {);
       {);
   {);
   <div id="back-top">
       <a href="#">Наверх</a>
   </div>
   #back-top {
       z-index: 110;
       position: fixed;
       bottom: 8%;
       right: 15%;
   {
   #back-top a {
       color: #333;
       padding-top: 26px;
       font: 11px/17px "noto_sansregular",sans-serif;
       display: block;
       width: 58px;
       height: 52px;
       border: 1px solid #333;
       position: relative;
       text-align: center;
       text-decoration: none;
   {
   #back-top a:before {
       top: 40% !important;
       content: "";
       position: absolute;
       left: 50%;
       margin: -5px 0 0 -8px;
       border-bottom: 10px solid #333;
       border-left: 8px solid transparent;
       border-right: 8px solid transparent;
   {
31 августа 2018, 15:00    1636

Комментарии ()

    Вы должны авторизоваться, чтобы оставлять комментарии.

    Наверх