Monday, 13 February 2023

How to solve 100vh problem in mobile

<script>
const appHeight = () => {
    const doc = document.documentElement
    doc.style.setProperty('--app-height', `${window.innerHeight}px`)
}
window.addEventListener('resize', appHeight)
appHeight()
</script>


:root {
    --app-height: 100%;
 }
 
 html,
 body {
     padding: 0;
     margin: 0;
     overflow: hidden;
     width: 100vw;
     height: 100vh;
     height: var(--app-height);
 }

Sunday, 24 April 2022

How to show popup only first visit of website

 <script>

                $(document).ready(function() {

                    var isshow = localStorage.getItem('isshow');

                    if (isshow== null) {

                        localStorage.setItem('isshow', 1);

                       // Show popup here

                        $('.popup').show();

                    }

                });

            </script>

Friday, 8 November 2019

Add class scroll up and scroll down the webpage

    <script>
        jQuery(document).ready(function(e) {
var position = jQuery(window).scrollTop();

// should start at 0
var x = jQuery("#pg-217-0").offset();
     var offt = x.top;
jQuery(window).scroll(function(e) {
    var scroll = jQuery(window).scrollTop();
   

    if(scroll < position && scroll > offt) {
        jQuery('#pg-217-0').addClass('stc');
    } else{
        
         jQuery('#pg-217-0').removeClass('stc');
    }
    position = scroll;
});
});
    </script>

Wednesday, 3 July 2019

How to scroll text down to up with css

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var hght = $(".scroll-up p").outerHeight();
    $(".scroll-up p").css("height",hght);
 
});
</script>


  <style type="text/css">
    .scroll-up {height: 200px; overflow: hidden; position: relative; background: none; color: orange; border: 0px solid orange;}
    .scroll-up p {position: absolute; width: 100%; /*height: 500px; */margin: 0; line-height: 25px; text-align: justified; font-size: 16px;overflow: hidden;
     /* Starting position */
     /*-moz-transform:translateY(100%);
     -webkit-transform:translateY(100%);   
     transform:translateY(100%);*/
     /* Apply animation to this element */   
     -moz-animation: scroll-up 30s linear infinite;
     -webkit-animation: scroll-up 30s linear infinite;
     animation: scroll-up 30s linear infinite;
    }

/* Move it (define the animation) */
@-moz-keyframes scroll-up {
 0%   { -moz-transform: translateY(200px); }
 100% { -moz-transform: translateY(-100%); }
}
@-webkit-keyframes scroll-up {
 0%   { -webkit-transform: translateY(200px); }
 100% { -webkit-transform: translateY(-100%); }
}
@keyframes scroll-up {
 0%   {
 -moz-transform: translateY(200px); /* Browser bug fix */
 -webkit-transform: translateY(200px); /* Browser bug fix */
 transform: translateY(200px);        
 }
 100% {
 -moz-transform: translateY(-100%); /* Browser bug fix */
 -webkit-transform: translateY(-100%); /* Browser bug fix */
 transform: translateY(-100%);
 }
}
</style>

<div class="scroll-up">
<p>
  <i>&#34;I&#39;ve enjoyed working with you during these past year. We did some great work and had some terrific outcomes. You&#39;ve been both, a great Business Partner but even more so you and your team became wonderful friends and I am sure we will see each other soon again&#34;.</i><br/>
  <span style="font-size: 14px; font-weight: bold; line-height: 14px; text-align: left">Manfred (Manny) Sablowski, Senior Vice President, Global Sales &#38; Marketing, Medovex Corp., Apr. 2019.</span><br/>
=============================<br/>
  <i>&#34;We were pleased with fast and professional handling. Good communication.</i><br/>
  <i>We will probably come back for some more business.&#34;</i><br/>
  <span style="font-size: 14px; font-weight: bold; line-height: 14px; text-align: left">Michael Cohn, MD, CEO, G.R. Dome Medical Ltd., Apr. 2019</span><br/>
=============================<br/>
  <i>&#34;Everyone at Medovex was thoroughly impressed with MediClever&#39;s work!&#34;</i><br/>
  <span style="font-size: 14px; font-weight: bold; line-height: 14px; text-align: left">Jesse Crowne, CEO, Medovex Corp., Dec. 2018</span><br/>
=============================<br/>
  <i>&#34;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</i><br/>
  <span style="font-size: 14px; font-weight: bold; line-height: 14px; text-align: left">John Doe, CEO, Medovex Corp., Dec. 2018</span><br/>
=============================<br/>
  <i>&#34;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo </i><br/>
  <span style="font-size: 14px; font-weight: bold; line-height: 14px; text-align: left">Kurtis Crowne, CEO, Medovex Corp., Dec. 2018</span><br/>
=============================<br/>
</p>
</div>

Thursday, 27 June 2019

Click doesn’t work after AJAX load – jQuery

jQuery(document).on('click', '#readmore', function(e){
    e.preventDefault();
    alert("you clicked the button");
    jQuery("#bodytext").css("display", "block");
});

Tuesday, 9 April 2019

jQuery load first 3 elements, click “load more” to display next 5 elements

<ul id="myList">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
<li>Nine</li>
<li>Ten</li>
<li>Eleven</li>
<li>Twelve</li>
<li>Thirteen</li>
<li>Fourteen</li>
<li>Fifteen</li> 
</ul>
<div id="loadMore">Load more</div>
 
<script> 
$(document).ready(function () {
    size_li = $("#myList li").size();
    x=3;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+5 <= size_li) ? x+5 : size_li;
        $('#myList li:lt('+x+')').show();
    });
    $('#showLess').click(function () {
        x=(x-5<0) ? 3 : x-5;
        $('#myList li').not(':lt('+x+')').hide();
    });
}); 
</script>



New JS to show or hide load more and show less


<script>
$(document).ready(function () {
    size_li = $("#myList li").size();
    x=3;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+5 <= size_li) ? x+5 : size_li;
        $('#myList li:lt('+x+')').show();
         $('#showLess').show();
        if(x == size_li){
            $('#loadMore').hide();
        }
    });
    $('#showLess').click(function () {
        x=(x-5<0) ? 3 : x-5;
        $('#myList li').not(':lt('+x+')').hide();
        $('#loadMore').show();
         $('#showLess').show();
        if(x == 3){
            $('#showLess').hide();
        }
    });
});
</script>

Wednesday, 27 March 2019

How to hide a DIV when the user clicks outside of it

<script>
jQuery(document).on('click', function (e) {
    if (jQuery(e.target).closest(".sle1").length === 0 && jQuery(e.target).closest(".city-filter").length === 0) {
        jQuery(".city-filter").slideUp();
        jQuery(".sle1").removeClass("active");
    }
});
</script>

Saturday, 23 March 2019

How do we apply jQuery for mobile only

 <script>
    $(document).ready(function () {
    $(window).on("resize", function (e) {
        checkScreenSize();
    });

    checkScreenSize();

    function checkScreenSize(){
        var newWindowWidth = $(window).width();
        if (newWindowWidth < 768) {
            jQuery(".recent-insight").insertAfter(".sidebar-right");
            $(".relateds .action-links ").insertBefore(".mob-block .vc_btn3-container");
        }else{
          $(".mob-block .action-links ").insertBefore(".relateds .vc_btn3-container");
        }
      
    }
});
  </script>

Thursday, 12 April 2018

How to create tabbing in jQuery

<!---------------------------------------------HTML---------------------------------------------->

<div class="container">

    <ul class="tabs">
        <li class="tab-link current" data-tab="tab-1">Tab One</li>
        <li class="tab-link" data-tab="tab-2">Tab Two</li>
        <li class="tab-link" data-tab="tab-3">Tab Three</li>
        <li class="tab-link" data-tab="tab-4">Tab Four</li>
    </ul>

    <div id="tab-1" class="tab-content current">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>
    <div id="tab-2" class="tab-content">
         Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
    <div id="tab-3" class="tab-content">
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    </div>
    <div id="tab-4" class="tab-content">
        Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>

</div><!-- container -->

<!--------------------------------------------css---------------------------------------------->

body{
            margin-top: 100px;
            font-family: 'Trebuchet MS', serif;
            line-height: 1.6
        }
        .container{
            width: 800px;
            margin: 0 auto;
        }



        ul.tabs{
            margin: 0px;
            padding: 0px;
            list-style: none;
        }
        ul.tabs li{
            background: none;
            color: #222;
            display: inline-block;
            padding: 10px 15px;
            cursor: pointer;
        }

        ul.tabs li.current{
            background: #ededed;
            color: #222;
        }

        .tab-content{
            display: none;
            background: #ededed;
            padding: 15px;
        }

        .tab-content.current{
            display: inherit;
        }




<!--------------------------------jQuery---------------------------------------------->

<script>
$(document).ready(function(){
   
    $('ul.tabs li').click(function(){
        var tab_id = $(this).attr('data-tab');

        $('ul.tabs li').removeClass('current');
        $('.tab-content').removeClass('current');

        $(this).addClass('current');
        $("#"+tab_id).addClass('current');
    })

})
</script>


Monday, 9 April 2018

Add two random class on body in jQuery

<script>
    $(document).ready(function(){
var classes = ["yellow", "pink"];

$("body").each(function(){
    $(this).addClass(classes[~~(Math.random()*classes.length)]);
});
});
</script>

Adding class randomly to HTML elements with jQuery

HTML

<div id="menu">
<ul>
    <li>Autos</li>
    <li>Real Estate</li>
    <li>Services</li>
    <li>Boats</li>
    <li>Gardening</li>
</ul>
</div>
 
<script>
$(document).ready(function(){
// create random number
  function randOrder() {
    return ( Math.round(Math.random())-0.5 ); 
  } 
 
$(document).ready(function() {
 
    // classses array
    var classes = [ 'li-one', 'li-two', 'li-three', 'li-four', 'li-five' ];
    // sort array elements randomly
    classes.sort( randOrder );
 
    // uncomment below to see order
    // alert( classes.sort( randOrd ) );
 
    // create loop to add each array element as a class
    $('#menu ul li').each(function(i, val) {
        $(this).addClass(classes[i]);
    });
});
});
</script> 

Wednesday, 4 April 2018

How to open dropdown menu on click

<script>
  jQuery(document).ready(function(){
    jQuery('#menu-mobile-menu li > .sub-menu').parent().click(function() {
  var submenu = jQuery(this).children('.sub-menu');
  var submenu2 = jQuery(this).children('.sub-menu-2');
  if ( jQuery(submenu).is(':hidden') ) {
    jQuery(submenu).slideDown(200);
jQuery(this).addClass("chev-down");
  } else {
    jQuery(submenu).slideUp(200);
jQuery(this).removeClass("chev-down");
  }
});
});
    </script>

Friday, 9 March 2018

Hide dropdown menu on click outside of the element in jquery

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Hide Dropdown on Click Outside</title>
<style type="text/css">
    ul{
        padding: 0;
        list-style: none;
        background: #f2f2f2;
    }
    ul li{
        display: inline-block;
        position: relative;
        line-height: 21px;
        text-align: left;
    }
    ul li a{
        display: block;
        padding: 8px 25px;
        color: #333;
        text-decoration: none;
    }
    ul li a:hover{
        color: #fff;
        background: #939393;
    }
    ul li ul.dropdown-menu{
        min-width: 100%; /* Set width of the dropdown */
        background: #f2f2f2;
        display: none;
        position: absolute;
        z-index: 999;
        left: 0;
    }
    ul li ul.dropdown-menu li{
        display: block;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        // Show hide popover
        $(".dropdown").click(function(){
            $(this).find(".dropdown-menu").slideToggle("fast");
        });
    });
    $(document).on("click", function(event){
        var $trigger = $(".dropdown");
        if($trigger !== event.target && !$trigger.has(event.target).length){
            $(".dropdown-menu").slideUp("fast");
        }           
    });
</script>
</head>
<body>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li class="dropdown">
            <a href="#">Products &#9662;</a>
            <ul class="dropdown-menu">
                <li><a href="#">Laptops</a></li>
                <li><a href="#">Monitors</a></li>
                <li><a href="#">Printers</a></li>
            </ul>
        </li>
        <li><a href="#">Contact</a></li>
    </ul>
</body>
</html>                           

Show/Hide Submenu item on click jquery

<nav>
  <ul class="nav">
    <li><a href="#">Menu item 1</a></li>
    <li><a href="#">Menu item 2</a></li>
    <li>
      <a href="#">Menu item with submenu</a>
      <ul class="sub-menu">
        <li><a href="#">Submenu item</a></li>
        <li><a href="#">Submenu item</a></li>
        <li><a href="#">Submenu item</a></li>
      </ul>
    </li>
  </ul>
</nav>

.nav li {
  list-style: none;
  padding: 5px 10px;
}

.nav > li {
  float: left;
}

.nav .sub-menu {
  display: none;
}


// Change 'click' to 'hover' if you want to
<script>
$(document).ready(function(){
$('.nav li > .sub-menu').parent().click(function() {
  var submenu = $(this).children('.sub-menu');
  if ( $(submenu).is(':hidden') ) {
    $(submenu).slideDown(200);
  } else {
    $(submenu).slideUp(200);
  }
});
});
</script>

Tuesday, 30 January 2018

Add class after some scroll and remove class when footer appear on screen window in jQuery

<script>
      jQuery(document).ready(function(e) {

    var screen_height = jQuery(window).height();

    var document_height = jQuery(document).height();

    var footer_height = jQuery(".footer").height();

     var max_scroll_height = document_height - screen_height;

    jQuery(window).on('scroll', function(e) {

        var scroll = jQuery(window).scrollTop();

        var element_in_view = scroll > 300;

        var has_reached_bottom_of_page = max_scroll_height - footer_height;

        if (scroll > 300 && scroll < has_reached_bottom_of_page) {

            jQuery('.btSidebar').addClass("changefixed");

        } else {

            jQuery('.btSidebar').removeClass("changefixed");
        }
    });
});
</script>

Friday, 8 September 2017

How to create bootstap nested accordion

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Accordion</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <style>
      .panel-body > a {color: #333; display: block; font-size: 16px; text-decoration: none;}
.panel-body {padding: 5px 30px;}
.panel-heading {background-color: transparent; border: medium none; color: #333; padding: 5px;}
.panel-title > a {display: block; text-decoration: none;}
.panel-default{border:none;}
.panel-title a {padding-left: 20px;}
.panel > a {color: #333; display: block; font-size: 16px; text-decoration: none;}
.plus-ic, .minus-ic {background-color: #333; border-radius: 50%; color: #fff; height: 20px; line-height: 20px; margin-right: 6px; text-align: center; width: 20px;}
a[aria-expanded="true"] .minus-ic{display: inline-block;}
a[aria-expanded="true"] .plus-ic{display: none;}
a[aria-expanded="false"] .plus-ic{display: inline-block;}
a[aria-expanded="false"] .minus-ic{display: none;}
.minus-ic{display: none;}

.collapseOne1 .plus-ic{display: none;}
.collapseOne1 .minus-ic{display: inline-block;}
.collapseOne1.collapsed .minus-ic{display: none;}
.collapseOne1.collapsed .plus-ic{display: inline-block;}
  </style>


</head>
<body>

<div class="panel-group" id="accordion1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion1" href="#collapseOne" class="collapseOne1"><span class="fa fa-plus plus-ic"></span><span class="fa fa-minus minus-ic"></span>My Account
                        </a>
                    </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <a href="my-account.php">My Account</a>
                        <a href="login-info.php">Login Info</a>
                        <a href="contact.php">Contact</a>
                        <a href="company.php">Company</a>
                        <a href="payment.php">Payment</a>
                        <a href="#">Travel</a>
                        <a href="#">Documents</a>
                        <a href="#">Reports</a>
                        <a href="#">Email Preferences</a>
                        <a href="#">Account Deactivation</a>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a href="#">My K-Method Certification </a>
                    </h4>
                </div>
               
            </div>

            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion1" href="#collapseTwo"><span class="fa fa-plus plus-ic"></span><span class="fa fa-minus minus-ic"></span>Profile Builder
                        </a>
                    </h4>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="panel-body">
                            <a href="my-resume.php"><span class="fa fa-exclamation-circle"></span> Resume</a>
                            <a href="about-me.php"><span class="fa fa-exclamation-circle"></span> About Me</a>
                            <a href="#"><span class="fa fa-exclamation-circle"></span> Skills</a>
                            <a href="#"><span class="fa fa-exclamation-circle"></span> Work Experience</a>
                            <a href="#"><span class="fa fa-exclamation-circle"></span> Certifications</a>
                            <a href="#"><span class="fa fa-exclamation-circle"></span> References</a>
                            <a href="#"><span class="fa fa-exclamation-circle"></span> Education</a>
                            <div class="panel-group" id="accordion21">
                                <div class="panel">
                                    <a data-toggle="collapse" data-parent="#accordion21" href="#collapseTwoOne"><span class="fa fa-plus plus-ic"></span><span class="fa fa-minus minus-ic"></span>Training Delivery
                                    </a>
                                    <div id="collapseTwoOne" class="panel-collapse collapse">
                                        <div class="panel-body">
                                            <a href="#">Courses</a>
                                            <a href="#">MCT Identification</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel ">
                                    <a data-toggle="collapse" data-parent="#accordion21" href="#collapseTwoTwo"><span class="fa fa-plus plus-ic"></span><span class="fa fa-minus minus-ic"></span>Design/Developement
                                    </a>
                                    <div id="collapseTwoTwo" class="panel-collapse collapse">
                                        <div class="panel-body">
                                            <a href="#">Authoring Tools</a>
                                            <a href="#">Work Samples</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


</body>
</html>

Saturday, 12 August 2017

How to open link of anchor tag on click of another div

<div class="nv"> click here </div>
 <a class="info_link" href="https://www.google.co.in/?gws_rd=ssl"> demo link</a>


<script>
      $(document).ready(function(){
    $(".nv").click(function() {
    var link = $(this).siblings("a").attr('href');
    window.location.href=link;
});
});
</script>

Friday, 21 July 2017

How to add attribute in HTML with jQuery

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   
        $("a").attr("target", "_blank");
   
});
</script>
</head>
<body>
<a href="http://naveenwebdesign.blogspot.in" id="nvn">Naveen web design</a>
</body>

Saturday, 1 July 2017

Show more and show less text button jQuery

<!--            HTML                     -->

<html>
  <head>
    <title>jQuery Read More/Less Toggle Example</title>
  </head>
  <body>
    <span class="more">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </span>
    <br><br>
    <div class="more">
      Morbi placerat imperdiet risus quis blandit. Ut lobortis elit luctus, feugiat erat vitae, interdum diam. Nam sit amet arcu vitae justo lacinia ultricies nec eget tellus. Curabitur id sapien massa. In hac <a href="#">habitasse</a> platea dictumst. Integer tristique leo consectetur libero pretium pretium. Nunc sed mauris magna. Praesent varius purus id turpis iaculis iaculis. Nulla <em>convallis magna nunc</em>, id rhoncus massa ornare in. Donec et feugiat sem, ac rhoncus mauris. Quisque eget tempor massa.
    </div>
  </body>
</html>

<!--     CSS      -->

.morecontent span {
    display: none;
}
.morelink {
    display: block;
}


<!--   jQuery  -->


$(document).ready(function() {
    // Configure/customize these variables.
    var showChar = 100;  // How many characters are shown by default
    var ellipsestext = "...";
    var moretext = "Show more >";
    var lesstext = "Show less";
   

    $('.more').each(function() {
        var content = $(this).html();

        if(content.length > showChar) {

            var c = content.substr(0, showChar);
            var h = content.substr(showChar, content.length - showChar);

            var html = c + '<span class="moreellipses">' + ellipsestext+ '&nbsp;</span><span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';

            $(this).html(html);
        }

    });

    $(".morelink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().toggle();
        $(this).prev().toggle();
        return false;
    });
});

Tuesday, 20 June 2017

How to apply simple parallax scrolling

function parallax(){
    var scrolled = $(window).scrollTop();
    $('.bg').css('top', -(scrolled * 0.2) + 'px');
}
$(window).scroll(function(e){
    parallax();
});