Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Need help with JS

qqxexqq

New Coder
Hello, im not really good at js so if some one know the solution pls help.
I found code, and its showing div block on scroll. But its working only with 1 block
How can i make working it for all blocks that i create with the same class
Thank you!

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>test</title>

    <style type="text/css">
    html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:700}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}
    body{
        margin: 0;
        padding: 0;
        text-align: left;
    }
    </style>
</head>
<body style="font-size: 14px; position: relative; padding: 15px 20px;">
    <div class="block">Content</div>
<div class="block">Content</div>
<div class="block">Content</div>

<div class="active">
    <div class="block">Content</div>
</div>

<div class="active">
    <div class="block">Content</div>
</div>

<div class="active">
    <div class="block">Content</div>
</div>
<style type="text/css">
.block {
    margin-bottom: 15px;
    background-image: linear-gradient(135deg, #ececec, #bfbbbb);
    padding: 100px 0;
    font-size: 44px;
    color: #555;
    text-align: center;
}
.active {
    margin: 0 -1% 15px;
    overflow: hidden;
}
.active div {
    display: none;
    float: left;
    width: 23%;
    margin: 1%;
    padding: 40px 0;
    background-image: linear-gradient(135deg, #ffaede, #ff9797);
    font-size: 60px;
    color: #fff;
    text-align: center;
}
</style>

<script src="https://snipp.ru/cdn/jquery/2.1.1/jquery.min.js"></script>
<script>
var block_show = false;

function scrollTracking(){
    if (block_show) {
        return false;
    }

    var wt = $(window).scrollTop();
    var wh = $(window).height();
    var et = $('.active').offset().top;
    var eh = $('.active').outerHeight();
    var dh = $(document).height();

    if (wt + wh >= et || wh + wt == dh || eh + et < wh){
        block_show = true;

        // Animation
        $('.active div:eq(0)').show('fast', function(){
            $(this).next().show('fast', arguments.callee);
        });
    }
}

$(window).scroll(function(){
    scrollTracking();
});

$(document).ready(function(){
    scrollTracking();
});
</script>
</body>
</html>
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom