Dẫn nhập
Ở bài trước, chúng ta đã tìm hiểu về JQUERY VÀ SET UP JQUERY CHO WEB LANDING PAGE .
Trong bài này, Kteam sẽ hướng dẫn bạn sử dụng jquery để làm một số hiệu ứng cho website của chúng ta. Nào! cùng bắt đầu với bài Code Stick Navigation và hiệu ứng Scroll.
Nội dung
Để đọc hiểu bài này tốt nhất, bạn nên xem qua các nội dung:
Trong bài này, Kteam sẽ cùng bạn tìm hiểu nội dung:
Code Stick Navigation Hiệu ứng Scroll
Code Stick Navigation
Style.css
.sticky {
background-color : rgba(2 ,33 ,64 ,.9 ) ;
top : 0 ;
left : 0 ;
width : 100 % ;
height : 70 px ;
}
.sticky .logo {
width : 250 px ;
margin-top : -40 px ;
}
.sticky .main-nav {
margin-top : 30 px ;
}
Scripts.js
$(document).ready(
function () {
$('.about-section' ).waypoint(
function (direction) {
if (direction == "down" ){
$('nav' ).addClass('sticky' );
}else {
$('nav' ).removeClass('sticky' );
}
},{
offset: '600px'
}
)
)
Hiệu ứng Scroll
Set thêm id cho từng section tương ứng thẻ a trong file index.html tương ứng các phần Home, About us, Testimonials, Sponsors, Contact.
Index.html
<!DOCTYPE html>
<html >
<head >
<title > Selftaught</title >
<link rel ="stylesheet" href ="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity ="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz"
crossorigin ="anonymous" >
<link href ="https://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel ="stylesheet" >
<link rel ="stylesheet" href ="vendors/css/grid.css" >
<link rel ="stylesheet" type ="text/css" href ="resources/css/styles.css" />
<link rel ="stylesheet" href ="resources/css/queries.css" >
</head >
<body >
<header id ="home" >
<nav >
<a href ="#home" > <img class ="logo" src ="./resources/img/logo.png" alt ="logo" > </a >
<ul class ="main-nav" >
<li > <a href ="#testimonials" > How Clients Think</a > </li >
<li > <a href ="#about" > About</a > </li >
<li > <a href ="#products" > Products</a > </li >
<li > <a href ="#contact" > Contact</a > </li >
</ul >
</nav >
<div class ="clearfix" > </div >
<div class ="row" >
<div class ="heading-main-box" >
<h1 >
We will study <br > English together.<br >
So join with us.
</h1 >
<a href ="#about" class ="btn" > Tell me more</a >
<a href ="#products" class ="btn" > Join us</a >
</div >
</div >
</header >
<section class ="about-section" id ="about" >
<div class ="row" >
<h2 > About Us</h2 >
<p class ="p-long" >
We are people that are studying English by ourselves, we believe that you don’t need to pay so much
money for being good at English, we’re here to help you
</p >
</div >
<div class ="row" >
<div class ="col span-1-of-4 about-picture" >
<img src ="./resources/img/activities1.jpeg" alt ="activities1" >
<p class ="picture-title" >
Team Working
</p >
</div >
<div class ="col span-1-of-4 about-picture" >
<img src ="./resources/img/activities2.jpeg" alt ="activities2" >
<p class ="picture-title" >
Funny class
</p >
</div >
<div class ="col span-1-of-4 about-picture" >
<img src ="./resources/img/activities3.jpeg" alt ="activities3" >
<p class ="picture-title" >
Be confident
</p >
</div >
<div class ="col span-1-of-4 about-picture" >
<img src ="./resources/img/activities4.jpeg" alt ="activities4" >
<p class ="picture-title" >
All our friends
</p >
</div >
</div >
</section >
<section class ="products-section" id ="products" >
<h2 > Products</h2 >
<div class ="row" >
<div class ="col span-1-of-3" >
<div class ="product-box" >
<h3 > Pronunciation class</h3 >
<p class ="product-price" > 19$ <span > / month</span > </p >
<ul >
<li > <i class ="fas fa-check small-icon" > </i > Native voices</li >
<li > <i class ="fas fa-check small-icon" > </i > Master IPA</li >
</ul >
<a href ="#" class ="btn" > JOIN US</a >
</div >
</div >
<div class ="col span-1-of-3" >
<div class ="product-box" >
<h3 > Speaking class</h3 >
<p class ="product-price" > 25$ <span > / month</span > </p >
<ul >
<li > <i class ="fas fa-check small-icon" > </i > Native speaking</li >
<li > <i class ="fas fa-check small-icon" > </i > Speaing naturally</li >
</ul >
<a href ="#" class ="btn" > JOIN US</a >
</div >
</div >
<div class ="col span-1-of-3" >
<div class ="product-box" >
<h3 > Listening class</h3 >
<p class ="product-price" > 25$ <span > / month</span > </p >
<ul >
<li > <i class ="fas fa-check small-icon" > </i > Native speech</li >
<li > <i class ="fas fa-check small-icon" > </i > Hearing English clearly</li >
</ul >
<a href ="#" class ="btn" > JOIN US</a >
</div >
</div >
</div >
</section >
<section class ="testimonials-section" id ="testimonials" >
<h2 > Testimonials</h2 >
<div class ="row" >
<div class ="col span-1-of-3" >
<blockquote >
The course is very helpful, I can speak English fluently and I think The SF English became my second family, I love everyone very much. Thank you!
<cite >
<img src ="resources/img/person5.jpeg" alt ="person1" > Nguyen Chem Gio
</cite >
</blockquote >
</div >
<div class ="col span-1-of-3" >
<blockquote >
I believe that who came to This English centre would love this place as I did, when the course finished, I feel sad because studying in that place I always felt funny.
<cite >
<img src ="resources/img/person2.jpeg" alt ="person1" > Tran Vo Van
</cite >
</blockquote >
</div >
<div class ="col span-1-of-3" >
<blockquote >
Trust me, you can master English just by joining this class, I did, so I believe that you can too. Hope that one day, you can come and join in this class.
<cite >
<img src ="resources/img/person4.jpeg" alt ="person1" > Le Du Do
</cite >
</blockquote >
</div >
</div >
</section >
<section class ="sponsors-section" id ="sponsors" >
<h2 > Sponsors</h2 >
<div class ="row" >
<ul class ="sponsors-showcase clearfix" >
<li >
<figure >
<img class ="logo-sponsor" src ="resources/img/barcelona_logo.png" alt ="barcelona" >
<figcaption >
Barcelona
</figcaption >
</figure >
</li >
<li >
<figure >
<img class ="logo-sponsor" src ="resources/img/mctcity_logo.png" alt ="manchester city" >
<figcaption >
Manchester City
</figcaption >
</figure >
</li >
<li >
<figure >
<img class ="logo-sponsor" src ="resources/img/tottenham_logo.png" alt ="tottenham hotspur" >
<figcaption >
Tottenham Hotspur
</figcaption >
</figure >
</li >
</ul >
<ul class ="sponsors-showcase clearfix" >
<li >
<figure >
<img class ="logo-sponsor" src="resources /img /real_logo.png " alt ="real marid" >
<figcaption >
Real Marid
</figcaption >
</figure >
</li >
<li >
<figure >
<img class ="logo-sponsor" src ="resources/img/juventus_logo.png" alt ="Juventus" >
<figcaption >
Juventus
</figcaption >
</figure >
</li >
<li >
<figure >
<img class ="logo-sponsor" src ="resources/img/mctunited_logo.png" alt ="manchester united" >
<figcaption >
Manchester United
</figcaption >
</figure >
</li >
</ul >
</div >
</section >
<section class ="contact-section" id ="contact" >
<div class ="row" >
<div class ="col span-1-of-3" >
<ul class ="information" >
<li > <i class ="fas fa-map-marker-alt small-icon" > </i > Address: 21A, SelfTaught street, Ha Noi</li >
<li > <i class ="fas fa-envelope small-icon" > </i > Email: selftaughtteam@edu.com</li >
<li > <i class ="fas fa-phone small-icon" > </i > SĐT: (+084 )099-923-232-320</li >
</ul >
<ul class ="social-icons" >
<li > <i class ="fab fa-facebook" > </i > </li >
<li > <i class ="fab fa-twitter-square" > </i > </li >
<li > <i class ="fab fa-instagram" > </i > </li >
<li > <i class ="fab fa-google-plus-square" > </i > </li >
</ul >
</div >
<div class ="col span-2-of-3" >
<form >
<div class ="row" >
<div class ="col span-1-of-3" >
<label > Name</label >
</div >
<div class ="col span-2-of-3" >
<input type ="text" placeholder ="Your Name" >
</div >
</div >
<div class ="row" >
<div class ="col span-1-of-3" >
<label > Email</label >
</div >
<div class ="col span-2-of-3" >
<input type ="email" placeholder ="Your Email" >
</div >
</div >
<div class ="row" >
<div class ="col span-1-of-3" >
<label > Message</label >
</div >
<div class ="col span-2-of-3" >
<textarea placeholder ="Your Message" > </textarea >
</div >
</div >
<div class ="row" >
<input type ="submit" class ="btn" value ="Send It" >
</div >
</form >
</div >
</div >
</section >
<footer >
<p >
Copyright © 2018 by SELFTAUGHT TEAM
</p >
</footer >
<script
src ="https://code.jquery.com/jquery-3.3.1.js"
integrity ="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin ="anonymous" > </script >
<script src ="vendors/js/jquery.waypoints.min.js" > </script >
<script src ="resources/js/scripts.js" > </script >
</body >
</html >
Scripts.js
$('a' ).click(function (event) {
$('html, body' ).animate({
scrollTop: $( $.attr(this , 'href' ) ).offset().top
}, 700 );
event.preventDefault();
});
}
Kết luận
Trong bài học này chúng ta đã hoàn thiện phần Stick Navigation và hiệu ứng Scroll.
Ở bài học sau chúng ta sẽ cùng code MOBILE NAVIGATION CHO WEBSITE.
Cảm ơn các bạn đã theo dõi bài viết. Hãy để lại bình luận và góp ý của mình để giúp phát triển bài viết tốt hơn. Đừng quên:
"Luyện tập – Thử thách – Không ngại khó" .
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Code Stick Navigation và hiệu ứng Scroll dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!
Project
Nếu việc thực hành theo hướng dẫn không diễn ra suôn sẻ như mong muốn. Bạn cũng có thể tải xuống PROJECT THAM KHẢO ở link bên dưới!
Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần BÌNH LUẬN bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
Hiện tại hình như cái script scroll treo taskbar home này bị lỗi rồi:
Mong Giảng viên có thể fix lại, hiện tại thêm đoạn mã position(:) fixed; z-index(:) 900; (Bỏ dấu ngoặc đơn) vào styles.css dùng tạm vẫn được, nhưng nó đóng băng đơ trên top khi scroll chứ ko linh hoạt như waypoint.Xin cảm ơn Giảng viên.