Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Artificial Intelligence (1)
  • Automobiles (12)
    • Cars (7)
  • Blog (104)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (56)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

CSSJavaScriptJQuery

One Thing Per Page Design using HTML, CSS, JavaScript and JQuery

By Admin
May 17, 2021 3 Min Read
0

Welcome to yet another interesting tutorial in which we will be designing a webpage. The webpage shows a single item in a single view and when scrolled jumps to another item.

Source Code

<script type="text/javascript" src="jquery.min.js"></script>
<link rel="stylesheet" href="bootstrap.min.css">


<style type="text/css">
  body{
    background:#ddd;
  }
  .box{
    padding-left:50px;
    padding-right:50px;
  }
  .template-wrapper{
    padding-top: 0px;
  }
  .slide{

    padding: 10px;
    margin-bottom: 10px;
    height:100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .description{
    text-align: justify;
  }
  html {
    scroll-behavior: smooth;
  }
  .image-wrapper img{
    width:100%;
  }
  .main-title{
    font-size: 38px;
      line-height: 50px;
      font-weight: bold;
  }
  .itemlist{
    background-color: #fff;
    padding:30px;
  }

</style>


<?php
  $list = array(
    array(
      'title'=>'Chennai defeat Hyderabad, keep their playoff hopes alive',
      'image'=>'https://letzcricket.com/uploads/news/SxE8UumjTKW4xylS.png',
      'description'=>'Shane Watson and Ambati Rayudu shared an 81-run stand as Chennai Super Kings beat Sunrisers Hyderabad by 20 runs in the Indian Premier League last night. With the win, Chennai has now 6 points from 8 games. Hyderabad also has 6 points from 8 games. Hyderabad is fifth and Chennai is sixth in the points table.'
    ),
    array(
      'title'=>'IPL 2021: Mumbai defeat Rajasthan by 7 wickets',
      'image'=>'https://letzcricket.com/uploads/news/LbJtYf7UAfmqCDtA.jpg',
      'description'=>'Defending champions defeated Rajasthan Royals by 7 wickets to register their third win in the ongoing 14th edition of Vivo Indian Premier League (IPL) on Thursday. Mumbai chased down a target of 172 runs with 7 wickets and 9 balls to spare.'
    ),
    array(
      'title'=>'Dhawan-Shaw starts as Delhi beat Chennai by 7 wickets',
      'image'=>'https://letzcricket.com/uploads/news/rixZxaDhm7fYxEji.png',
      'description'=>'Openers Shikhar Dhawan and Prithvi Shaw shined bright with the bat as Delhi Capitals started their IPL 2021 campaign with an impressive win over Chennai Super Kings on Saturday.'
    ),
    array(
      'title'=>'Stoinis, Rabada guide Delhi to a win over Bangalore',
      'image'=>'https://letzcricket.com/uploads/news/CfdMmHTYvK6ckYnc.png',
      'description'=>'Delhi Capitals (DC) registered a comprehensive victory over Royal Challengers Bangalore (RCB) in the ongoing 13th edition of Indian Premier League (IPL) on Monday. RCB were restricted to 137/9 in 20 overs chasing a target of 197 runs to win eventually handing a 59 run victory to Delhi.'
    ),
    array(
      'title'=>'Bhuvneshwar Kumar to miss rest of IPL',
      'image'=>'https://letzcricket.com/uploads/news/UILlUtNhwRbeeTLH.png',
      'description'=>'Injured fast bowler Bhuvneshwar Kumar is set to miss the rest of the Indian Premier League (IPL) this season. Sunrisers Hyderabad confirmed this on Tuesday. He suffered a thigh injury in the match against Chennai Super Kings in Dubai on Friday.'
    ),
    array(
      'title'=>'Universe Boss Gayle likely to be back on Thursday',
      'image'=>'https://letzcricket.com/uploads/news/VkQppy4Xmbbp6egH.png',
      'description'=>'Kings XI Punjab batsman Chris Gayle is likely to feature in the playing elevenfrom the eighth match of the ongoing Indian Premier League. Punjab has stated that Gayle, who has been sitting on the bench due to stomach problems, is ready to take the field from Thursday.'
    )		
  );
?>

  <div class="template-wrapper">
    <div class="box">
      <div class="list-container" style="transition: all 1s ease 0s;">
        <?php $i=0; foreach($list as $l){ $i++;?>
          <div class="<?php if($i==1){ echo 'active-slide';}?> slide">
            <div class="items itemlist row">
              <figure class="image-wrapper col-md-6">
                <img src="<?php echo $l['image'];?>" alt="<?php echo $l['title'];?>">
              </figure>
              <div class="col-md-6">
                <h1 class="main-title">
                  <?php echo $l['title'];?>
                </h1>
                <br>
                <div class="description-box">
                  <div class="description">
                    <span><?php echo $l['description'];?></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        <?php } ?>
      </div>
    </div>
  </div>


<script>
  var running = false;
  
  document.getElementsByClassName('slide')[0].classList.add('active-slide');

  var scrollableElement = document.getElementsByClassName('list-container')[0];

  scrollableElement.addEventListener('wheel', checkScrollDirection);

  function checkScrollDirection(event) {
    event.preventDefault();
    if(!running){
      running = true;
      if (checkScrollDirectionIsUp(event)) {
        prev();
      } else {
        next();
      }
    }
  }

  function next(){
    next_slide = $('.active-slide').next('.slide');
    scrollToView(next_slide);
  }

  function prev(){
    previous_slide = $('.active-slide').prev('.slide');
    scrollToView(previous_slide);
  }

  function scrollToView(element){
    if(element.length>0){
      $(".active-slide").removeClass('active-slide');
      element.addClass('active-slide');
      $('html, body').animate({
        scrollTop: $(element).offset().top-20
      });
      setTimeout(function(){
        running = false;
      },800);
    }
  }

  function checkScrollDirectionIsUp(event) {
    if (event.wheelDelta) {
      return event.wheelDelta > 0;
    	}
    	return event.deltaY < 0;
  }

  document.onkeydown = checkKey;

  function checkKey(e) {

      e = e || window.event;

      if (e.keyCode == '38') {
          prev();
      }
      else if (e.keyCode == '40') {
          next();
      }
      else if (e.keyCode == '37') {
         prev();
      }
      else if (e.keyCode == '39') {
         next();
      }
      else if(e.keyCode === 34){
     		next();
        }
        else if(e.keyCode === 33){
     		prev();
        }

  }

  scrollToView($('.active-slide'));
</script>

 

Follow this video for complete guidance :

Tags:

designone thing per page
Author

Admin

Follow Me
Other Articles
Previous

Draggable HTML Element using pure JavaScript

Next

Access Camera and Read QR code using JavaScript

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Over 10,000 Nepali Students to Join First-Ever National Innovation League
  • AI Journalism Workshop Held in Kathmandu by CAN Federation and TBAN
  • ChatGPT vs Gemini vs Claude AI: 7 Crucial Differences Revealed
  • CAN Federation Partners with FEJA to Host Exclusive ‘AI in Journalism’ Workshop
  • Shramik Shanti Campus Hosts Workshop on AI in Cybersecurity and Sovereign AI

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Over 10,000 Nepali Students to Join First-Ever National Innovation League Admin
  • AI Journalism Workshop Held in Kathmandu by CAN Federation and TBAN Admin
  • ChatGPT vs Gemini vs Claude AI: 7 Crucial Differences Revealed Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme