jquery的应用

jquery的总结

  1. 图片高度自适应:
$(function(){
   $("img").addClass("img-responsive center-block")
})
  1. 返回顶部效果
<head>
 	<style>
	 .stick{
	    position: fixed;
	    bottom: 100px;
	    right: 50px;
	    width: 50px;
	    display: flex;
	    flex-direction: column;
	    opacity: 0;
	    transform: translateX(150px);
	    z-index: 99;
 	    transition: all 0.5s;
	  }
	  /* show是通过jquery添加的样式- */
	  .show{ 
	    transform:none;
	    opacity: 1;
	  }
	  .stick>a{
	    width: 100%;
	    height: 50px;
	    border-radius: 50%;
	    background: #F97E05;
	    position: relative;
	    display: flex;
	    align-items: center;
	    justify-content: center;
	    margin-bottom: 10px;
	    z-index: 100;
	  }
	  .stick>a ul{
	    width: 0;
	    position: absolute;
	    top: 0;
	    right: 50%;
	    height: 50px;
	    display: flex;
	    background: #F97E05;
	    padding: 0 10px;
	    border-top-left-radius: 50px;
	    border-bottom-left-radius: 50px;
	    overflow: hidden;
	    z-index: -1;
	    opacity: 0;
	    transition: all 0.5s;
	  }
	  .stick>a ul li{
	    display: flex;
	    align-items: center;
	    margin-right: 15px;
	  }
	  .stick>a ul li span{
	    display: flex;
	    white-space: nowrap;
	    color: #fff;
	  }
	  .stick-btn:hover>ul{
	    opacity: 1;
	    width: 100px;
	  }
	  .stick i{   
	    margin-right: 10px;
	    margin-left: 10px;
	    color: #fff;
	    font-size: 25px;
	  }
	  .stick-btn li{
	    margin-left: 10px;
	  }
	</style>
</head>
<body>
	<div class="stick">
      <a class="stick-btn">
         <i class="iconfont icon-fanhuidingbu"></i>
         <ul>
           <li>
             <span>返回顶部</span>
           </li>
         </ul>
       </a>
    </div>
    <script>
		$(function(){
			$(".stick-btn").on("click",function(e){
				e.preventDefault();  //阻止事件的默认行为
				$("html,body").animate({scrollTop:"0px"},500);    // 滚动条跳到0的位置,页面移动速度500
				// $("html,body").animate({scrollTop:$(".footer).offset().top},500)  //返回底部
				return false;
			});
			var offset = $(window).height() - 100;
			$(window).on("scroll",function(){
				// scrollTop() 方法返回或设置匹配元素的滚动条垂直位置
				// offset:可选,规定相对滚动条顶部的偏移的位置
				if ($(this).scrollTop() > offset){
					$(".stick").addClass("show")
				} else {
					$(".stick").removeClass("show")	
				}
			})
		})
	</script>
</body>

效果:①当滚动条滚动到一定位置,页面右下角出现这个返回顶部的按钮
在这里插入图片描述
效果:②当鼠标悬停在这个图标上时,左侧滑出返回顶部字样,点击这个图标时页面到返回顶部
在这里插入图片描述
3.轮播图(基于bootstrap)

<head>
	<style>
		.swiper-container0{
    		width: 100%;
		}
		.swiper-container0 img{
		    width: 100%;
		    height: auto;
		    object-fit:cover;
		}
		@media (max-width: 1900px){
		    .swiper-container{
		        width: 100%;
		    }
		}
	</style>
</head>
<body>	
	<div class="swiper-container swiper-container0" style="width:100%;">
	    <div class="swiper-wrapper">
	      <div class="swiper-slide"><img class="img-responsive center-block" src="images/banner_1.jpg"></div>
	      <div class="swiper-slide active"><img class="img-responsive center-block" src="images/banner_2.jpg"></div>
	      <div class="swiper-slide"><img class="img-responsive center-block" src="images/banner_3.jpg"></div>
	      <div class="swiper-slide"><img class="img-responsive center-block" src="images/banner_4.jpg"></div>
	      <div class="swiper-slide"><img class="img-responsive center-block" src="images/banner_5.jpg"></div>
	    </div>
	    <div class="swiper-pagination"></div>
	    <div class="swiper-button-prevs" aria-disabled="false"><i class="iconfont icon-zuofanye-xue"></i></div>
	    <div class="swiper-button-nexts" aria-disabled="false"><i class="iconfont icon-youfanye-xue"></i></div>
	  </div>	
	  <script>	
			// 计算窗口高度
			$(function(){	
				if($(window).width<=1024px){
					$(".swiper-container0 img").css({"height" : "auto"});
				}	
			})	
			
			var swiper = new Swiper(".swiper-container0",{
				slidesPerView: 1,
				spaceBetween: 0,
				autoplay: {
					delay: 2500, //轮播速度
					disableOnInteraction: false,	
				},
				pagination: {
					el: ".swiper-pagination",
					clickable: true,	
				},
				navigation: {	
					nextEl: ".swiper-button-nexts",
					prevEl: ".swiper-button-prevs",	
				}
			})
	  </script>
</body>

效果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值