HTML5----图片或文字指定位子隐藏到显示动态效果

图片或文字隐藏到显示动态效果


各小图从一个位子过度移动显示到指定位子


CSS:

left0{position:absolute;top:0px; left:100px;

opacity: 0;filter:alpha(opacity=1);
-webkit-transition: all 1.2s ease .6s;
-moz-transition: all 1.2s ease .6s;
transition: all 1.2s ease .6s;

/*以下为自转动画*/
/* webkit chrome, safari, mobile */  
-webkit-animation-name: spin;   
-webkit-animation-duration: 12s;
-webkit-animation-iteration-count: 1;   /*1:自转一周; infinite:无限的自转*/
-webkit-animation-timing-function: linear;  

/* mozilla ff */  
-moz-animation-name: spin;   
-moz-animation-duration: 12s; 
-moz-animation-iteration-count: 1;   
-moz-animation-timing-function: linear;  

/* microsoft ie */  
-ms-animation-name: spin;   
-ms-animation-duration: 12s; 
-ms-animation-iteration-count: 1;   
-ms-animation-timing-function: linear; 

/* Opera */  
-o-animation-name: spin;   
-o-animation-duration: 12s; 
-o-animation-iteration-count: 1;   
-o-animation-timing-function: linear; 
}

.danmian { opacity: 1; filter:alpha(opacity=100);}

.mob-bd .anim .danmian .left0{ left:-40px}    /*将从左-40px向0px过度平滑显示*/

/**------按钮--0.3s过度到显示----------**/
.download-button:hover
{ background:#00aeff; 
-webkit-transition: all .5s ease .3s;
-moz-transition: all .5s ease .3s;
transition: all .5s ease .3s;
}



滑到一指定高度响应事件

JS:

<script type="text/javascript">
$(window).scroll( function(){
		scrollList();
})
function scrollList(){
	if($(window).scrollTop() > 140){
		$('.left0').addClass('danmian');}		
	if($(window).scrollTop() > 240){
		$('.left1').addClass('danmian');}

}
scrollList();
</script>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在SwiftUI中,我们可以使用ScrollView的scrollTo方法来将滚动视图自动滚动到指定位置。使用scrollTo方法需要指定要滚动到的位置,这个位置可以是某个具体的视图,也可以是某个偏移量。 下面是一个示例代码,用于将ScrollView自动滚动到指定位置: ```swift struct ContentView: View { let itemCount = 20 // 列表项数量 @State var selectedItem: Int? // 当前选中的列表项 var body: some View { ScrollView { VStack(spacing: 20) { ForEach(0..<itemCount) { index in Button("Item \(index+1)") { selectedItem = index // 点击时选中该列表项 scrollToSelected() // 滚动到选中的列表项 } .frame(maxWidth: .infinity, maxHeight: 50) .background(selectedItem == index ? Color.blue : Color.gray) .foregroundColor(.white) } } .padding() } } func scrollToSelected() { withAnimation { guard let selectedItem = selectedItem else { return } let selectedRect = CGRect(x: 0, y: CGFloat(selectedItem) * 70, width: 1, height: 1) // 计算选中项的位置 ScrollViewReader { scrollView in scrollView.scrollTo(selectedRect, anchor: .top) // 滚动到选中项 } } } } ``` 在这个示例代码中,我们首先创建了一个包含多个按钮的ScrollView,并且使用一个状态变量selectedItem来记录当前选中的列表项。当用户点击某个列表项时,我们会将selectedItem设置为该项的索引,并且调用scrollToSelected方法来将ScrollView自动滚动到选中的列表项。 在scrollToSelected方法中,我们首先使用withAnimation修饰符来启用动画效果。然后,我们根据选中项的索引计算出该项的位置,创建一个CGRect对象,然后使用ScrollViewReader和scrollTo方法来将ScrollView滚动到该位置。 需要注意的是,scrollTo方法需要在ScrollViewReader的闭包中调用,因为只有在该闭包中才能访问到ScrollView的实例。此外,需要指定anchor参数来指定滚动位置的对齐方式,这里我们使用了.top来将选中项的顶部对齐到ScrollView的顶部。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值