网站建设资讯

NEWS

网站建设资讯

html5滚动样式的简单介绍

如何使用HTML5实现横向滚动?

实现原理:

澄海ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

1. 利用CSS3的@keyframes规则创建动画效果;

2. 使用CSS3的animation效果完成滚动切换。

1 @-webkit-keyframes scrollText2 {

2 0%{

3 -webkit-transform: translateX(0px);

4 }

5 20%{

6 -webkit-transform: translateX(-204px);

7 }

8 40%{

9 -webkit-transform: translateX(-408px);

10 }

11 60%{

12 -webkit-transform: translateX(-612px);

13 }

14 80%{

15 -webkit-transform: translateX(-816px);

16 }

17 100%{

18 -webkit-transform: translateX(-1020px);

19 }

20 }

21 @keyframes scrollText2 {

22 0%{

23 transform: translateX(0px);

24 }

25 20%{

26 transform: translateX(-204px);

27 }

28 40%{

29 transform: translateX(-408px);

30 }

31 60%{

32 transform: translateX(-612px);

33 }

34 80%{

35 transform: translateX(-816px);

36 }

37 100%{

38 transform: translateX(-1020px);

39 }

40 }

41

42 .box4{

43 position: absolute;

44 top: 100px;

45 left: 100px;

46 width: 200px;

47 height: 30px;

48 overflow: hidden;

49 }

50 .border4{

51 position: absolute;

52 top: 0px;

53 left: 0px;

54 width: 1400px;

55 -webkit-animation:scrollText2 12s infinite cubic-bezier(1,0,0.5,0) ;

56 animation:scrollText2 12s infinite cubic-bezier(1,0,0.5,0) ;

57 }

58 .border4 div{

59 height: 30px;

60 width: 200px;

61 overflow: hidden;

62 display: inline-block;

63 }

64 .border4:hover{

65 animation-play-state:paused;

66 -webkit-animation-play-state:paused;

67 }

CSS代码说明:

@-webkit-keyframes及@keyframes定义了从0% ~ 100%之间,每过20%的时间,向左移动204px,总共有6次移动;

.box4 定义外容器的基本属性

.border4 定义了内容器的属性,-webkit-animation:scrollText1 12s infinite cubic-bezier(1,0,0.5,0) 和 animation:scrollText1 12s infinite cubic-bezier(1,0,0.5,0) 定义了用12s种循环一次,无限循环的效果;

.border4 div 定义了纵向滚动内容的基本样式;

.border4:hover 定义了鼠标移入容器时的效果,animation-play-state:paused 及 -webkit-animation-play-state:paused 定义了动画暂停;

1 div class="box4"

2 div class="border4"

3 divThis is a test 1./div

4 divThis is a test 2./div

5 divThis is a test 3./div

6 divThis is a test 4./div

7 divThis is a test 5./div

8 divThis is a test 1./div

9 /div

10 /div

HTML代码说明:

定义了6条信息可以横向滚动,其中前5条是真正横向滚动的信息,第6条和第1条信息是一样的,原因和上一篇纵向滚动一样,因为使用了@keyframes方式来实现动画效果,第1条信息的效果是默认为停止的,所以用第6条信息制作一个替代方法,在第一次循环结束后,可以无缝继续滚动。

如何用html5实现左侧是滚动菜单,选中后右边呈现效果

这问题好纠结,最少来个截图啊,给你写个吧,粘过去就行,不行的话留个q,继续问

!DOCTYPE html

html

head

meta charset="utf-8" /

title选项卡/title

style type="text/css"

::-webkit-scrollbar{width:0px}

*{ margin:0; padding:0}

ul{

list-style: none;

}

.tab{ 

width: 600px;

margin: 80px auto;

}

.tab .tab_menu{

float:left;

height: 138px;

width: 90px; 

overflow-y:scroll;

}

.tab .tab_menu ul{width:60px;}

.tab .tab_menu ul li{

width: 60px;

text-align: center;

line-height: 30px;

}

.tab .tab_menu ul li:last-child{

border-right:none;

width:60px;

}

.tab .tab_menu ul li.on{

background: #999;

}

.tab_box{float:left;}

.tab .tab_box  div{

width: 300px;

height: 138px;

border:1px solid #6cf;

display: none; //将三个内容框架全隐藏,通过下面的:first-child属性只将第一个框架内容显示出来

}

.tab .tab_box  div:first-child{

display: block;

}

/style

/head

body

!--整体构局说明,用ul完成按钮的横向布局,用div完成三个内容框架的垂直布局(类似于类表),然后将三个内容框架全隐藏,通过下面的:first-child属性只将第一个框架内容显示出来--

div class="tab"

div class="tab_menu"

ul

li class="on"实事/li

li政治/li

li体育/li

li实事/li

li政治/li

li体育/li

li实事/li

li政治/li

li体育/li

li实事/li

li政治/li

li体育/li

/ul

/div

div class="tab_box"

div实事内容/div

div政治内容/div

div体育内容/div

div实事内容/div

div政治内容/div

div体育内容/div

div实事内容/div

div政治内容/div

div体育内容/div

div实事内容/div

div政治内容/div

div体育内容/div

/div

/div

script type="text/javascript" src=""/script

script type="text/javascript"

$(function(){

$(".tab_menu ul li").click(function(){

$(this).addClass("on").siblings().removeClass("on"); //切换选中的按钮高亮状态

var index=$(this).index(); //获取被按下按钮的索引值,需要注意index是从0开始的

$(".tab_box  div").eq(index).show().siblings().hide(); //在按钮选中时在下面显示相应的内容,同时隐藏不需要的框架内容

});

});

/script

/body

/html

HTML5中,是怎么实现滚动图片的?

把要实现滚动图片的图片进行重叠,再利用javascript实现滚动效果,left-=*px,或者left+=*px

HTML5怎么设置滚动字幕?

marquee direction=up behavior=scroll loop=3 scrollamount=1 scrolldelay=10 align=top bgcolor=#ffffff height=300 width=30% hspace=20 vspace=10 onmouseover=this.stop() onmouseout=this.start() 此处输入滚动内容 /marquee

◎ direction表示滚动的方向,值可以是left,right,up,down,默认为left

◎ behavior表示滚动的方式,值可以是scroll(连续滚动)slide(滑动一次)alternate(往返滚动)

◎ loop表示循环的次数,值是正整数,默认为无限循环

◎ scrollamount表示运动速度,值是正整数,默认为6

◎ scrolldelay表示停顿时间,值是正整数,默认为0,单位似乎是毫秒

◎ align表示元素的垂直对齐方式,值可以是top,middle,bottom,默认为middle

◎ bgcolor表示运动区域的背景色,值是16进制的RGB颜色,默认为白色

◎ height、width表示运动区域的高度和宽度,值是正整数(单位是像素)或百分数,默认width=100% height为标签内元素的高度

◎ hspace、vspace表示元素到区域边界的水平距离和垂直距离,值是正整数,单位是像素。

◎ onmouseover=this.stop() onmouseout=this.start()表示当鼠标以上区域的时候滚动停止,当鼠标移开的时候又继续滚动。

html5上下滑动“翻页”实现,是真正的翻页

HTML5手机上下滑动翻页特效是一款手机移动端触屏滑动效果实现完整代码如下:

1、html5页面代码

!DOCTYPE html

htmlheadmeta http-equiv="Content-Type" content="text/html; charset=UTF-8"

titleHTML5手机页面触屏滑动上下翻页特效/title

meta charset="utf-8"

meta name="apple-touch-fullscreen" content="YES"

meta name="format-detection" content="telephone=no"

meta name="apple-mobile-web-app-capable" content="yes"

meta name="apple-mobile-web-app-status-bar-style" content="black"

meta http-equiv="Expires" content="-1"

meta http-equiv="pragram" content="no-cache"

link rel="stylesheet" type="text/css" href="./hamer_files/main.css"

link rel="stylesheet" type="text/css" href="./hamer_files/endpic.css"

script type="text/javascript" src="./hamer_files/offline.js"/script

meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi"

/head

body class="s-bg-ddd pc no-3d perspective yes-3d" style="-webkit-user-select: none;"

section class="u-alert"

  img style="display:none;" src="./hamer_files/loading_large.gif"

  div class="alert-loading z-move"

      div class="cycleWrap" span class="cycle cycle-1"/span

          span class="cycle cycle-2"/spanspan class="cycle cycle-3"/spanspan class="cycle cycle-4"/span

      /div

      div class="lineWrap" span class="line line-1"/spanspan class="line line-2"/spanspan class="line line-3"/span

      /div

  /div

/section

section class="u-arrow"

  p class="css_sprite01"/p

/section

section class="p-ct transformNode-2d transformNode-3d" style="height: 918px;"

  div class="translate-back" style="height: 918px;"

      div class="m-page m-fengye" data-page-type="info_pic3" data-statics="info_pic3" style="height: 918px;"

          div class="page-con lazy-finish" data-position="50% 50%" data-size="cover" style="height: 920px; background-image: url(hamer_files/1.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/2.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/3.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/4.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/5.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/6.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/7.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

      div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"

          div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/8.jpg); background-size: cover; background-position: 50% 50%;"/div

      /div

  /div

/section

section class="u-pageLoading"

  img src="./hamer_files/load.gif" alt="loading"

/section

script src="./hamer_files/init.mix.js" type="text/javascript" charset="utf-8"/script

script src="./hamer_files/coffee.js" type="text/javascript" charset="utf-8"/script

script src="./hamer_files/99_main.js" type="text/javascript" charset="utf-8"/script

/body/html

2、css代码:

@charset "utf-8";

.ad_foot li { margin:0 auto 1em; font-size:1.8em; padding:15px; background:#FFF;}

.ad_foot li a {display:block;}

.ad_foot li .l {width:75px; height:75px; float:left; overflow:hidden;}

.ad_foot li .l img {width:75px; width:75px;}

.ad_foot li .r {width:78%; float:left; margin-left:30px; color:#666; overflow:hidden;}

.ad_foot li .r p {color:#999; font-size:1.2em; }

.ad_foot li .r span {font-size:0.8em;}

.ad_foot li .r i {font-style:normal;}

.lazy-img, .lazy-finish{background-color:#f0eded;}

.page-list{font-size:20px;font-family: "Microsoft yahei";padding-left:17px;padding-top:30px;height:35px;border-bottom:1px solid #b5b5b5;display:none;}

.ad_foot{padding:15px 15px 0 15px;}

/*声音播放按钮*/

#song_img {width:293px; height:41px; display:block; position:absolute; right:4.1em; top:1.6em; font-size:1.7em; text-align:center; line-height:41px; color:#FFF; background:url(../img/music_c3.png) no-repeat 0 0;}

/*底部推荐*/

.ad_list{margin-top:2em;}.ad_list li {width:46%; background:none; padding:0; float:left;margin-bottom: 1em;}

.ad_list li.r {float:right;}.ad_list li a img {width:100%; height:auto;}

.ad_foot h3 {width:100%; height:48px; line-height:48px; background:#F9F5EC;}

.ad_foot h3 a {display:inline-block; color:#444; width:50%; text-align:center; font-size:1.5em; height:48px; border-bottom:2px solid #FF9240;}

.ad_foot h3 a.active {color:#FFF; background:#FF9240;}

.magazine_1 li {

width:100%;

margin-bottom: 1em;

font-size: 1.8em;

padding: 15px;

background: #FFF;}

.magazine_1 li a {display:block;}

.magazine_1 li .l {width: 75px;

height: 75px;

float: left;

overflow: hidden;}

.magazine_1 li .l img {width:75px; height:75px;}

.magazine_1 li .r {width: 78%;

float: left;

margin-left: 30px;

color: #666;

overflow: hidden;}

.magazine_1 li .r p {

color: #999;

font-size: 1.2em;

.magazine_1 li .r span {font-size:0.8em;}

.ad_foot li .r i {font-style:normal;}

3、运行效果如下:

html5怎么实现页面左右滑动(下图区域),可以左右滑动但不需要换页

1、创建两个html文件,一个test一个test2。

2、打开test页面,在里面创建一个div,并给其添加onmousedown与move方法。

3、打开后我们发现是一个棕绿的页面。

4、定义两个变量,startx为鼠标按下的坐标,endx为鼠标移动的坐标。

5、实现鼠标点击执行的down方法,在里面通过clientX获得鼠标按下坐标,并赋值给startx。

6、接着在实现鼠标移动的move方法,获得鼠标移动的坐标,并通过startx与endx相减判断是否向左边滑动大于30的距离,是的话就切换到test2页面。

7、现在我们打开test页面,向左滑动会提示切换页面(这个可以去除),确定后就切换到了test2页面,向右滑动切换的方法同理。


本文题目:html5滚动样式的简单介绍
标题网址:http://cdweb.net/article/dscoded.html