当前位置:首页 > 代码 > 正文

html5触屏特效代码(html5效果)

admin 发布:2022-12-20 00:21 147


今天给各位分享html5触屏特效代码的知识,其中也会对html5效果进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Html5支持iPhone触屏的脚本应该怎么写

Html5支持iPhone触屏的脚本写法是利用touch事件方法。 触摸事件(touch)会在用户手指放在屏幕上面的时候、在屏幕上滑动的时候或者是从屏幕上移开的时候出发。下面具体说明: touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发。 touchmove事件:当手指在屏幕上滑动的时候连续地触发。在这个事件发生期间,调用preventDefault()事件可以阻止滚动。 touchend事件:当手指从屏幕上离开的时候触发。 touchcancel事件:当系统停止跟踪触摸的时候触发。关于这个事件的确切出发时间,文档中并没有具体说明,咱们只能去猜测了。 示例代码如下:function load (){document.addEventListener('touchstart',touch, false);document.addEventListener('touchmove',touch, false);document.addEventListener('touchend',touch, false);function touch (event){var event = event window.event;var oInp = document.getElementById("inp");switch(event.type){case "touchstart":oInp.innerHTML = "Touch started (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";break;case "touchend":oInp.innerHTML = "br/Touch end (" + event.changedTouches[0].clientX + "," + event.changedTouches[0].clientY + ")";break;case "touchmove":event.preventDefault();oInp.innerHTML = "br/Touch moved (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";break;}} } window.addEventListener('load',load, false);

HTML5动画特效怎么做

主要思想:

首先要准备一张有连续帧的图片,然后利用HTML5 Canvas的draw方法在不同的时间间隔绘制不同的帧,这样看起来就像动画在播放。

关键技术点:

JavaScript 函数setTimeout()有两个参数,第一个是参数可以传递一个JavaScript方法,

另外一个参数代表间隔时间,单位为毫秒数。代码示例:

setTimeout( update, 1000/30);

Canvas的API-drawImage()方法,需要指定全部9个参数:

ctx.drawImage(myImage, offw, offh, width,height, x2, y2, width, height);

其中offw, offh是指源图像的起始坐标点,width, height表示源图像的宽与高,x2,y2表

示源图像在目标Canvas上的起始坐标点。

!DOCTYPE html 

html 

head 

meta http-equiv="X-UA-Compatible" content="chrome=IE8" 

meta http-equiv="Content-type" content="text/html;charset=UTF-8" 

titleCanvas Mouse Event Demo/title 

link href="default.css" rel="stylesheet" / 

script 

var ctx = null; // global variable 2d context 

var started = false; 

var mText_canvas = null; 

var x = 0, y =0; 

var frame = 0; // 22 5*5 + 2 

var imageReady = false; 

var myImage = null; 

var px = 300; 

var py = 300; 

var x2 = 300; 

var y2 = 0; 

window.onload = function() { 

var canvas = document.getElementById("animation_canvas"); 

console.log(canvas.parentNode.clientWidth); 

canvas.width = canvas.parentNode.clientWidth; 

canvas.height = canvas.parentNode.clientHeight; 

if (!canvas.getContext) { 

console.log("Canvas not supported. Please install a HTML5 compatible browser."); 

return; 

// get 2D context of canvas and draw rectangel 

ctx = canvas.getContext("2d"); 

ctx.fillStyle="black"; 

ctx.fillRect(0, 0, canvas.width, canvas.height); 

myImage = document.createElement('img'); 

myImage.src = "../robin.png"; 

myImage.onload = loaded(); 

function loaded() { 

imageReady = true; 

setTimeout( update, 1000/30); 

function redraw() { 

ctx.clearRect(0, 0, 460, 460) 

ctx.fillStyle="black"; 

ctx.fillRect(0, 0, 460, 460); 

// find the index of frames in image 

var height = myImage.naturalHeight/5; 

var width = myImage.naturalWidth/5; 

var row = Math.floor(frame / 5); 

var col = frame - row * 5; 

var offw = col * width; 

var offh = row * height; 

// first robin 

px = px - 5; 

py = py - 5; 

if(px  -50) { 

px = 300; 

if(py  -50) { 

py = 300; 

//var rate = (frame+1) /22; 

//var rw = Math.floor(rate * width); 

//var rh = Math.floor(rate * height); 

ctx.drawImage(myImage, offw, offh, width, height, px, py, width, height); 

// second robin 

x2 = x2 - 5; 

y2 = y2 + 5; 

if(x2  -50) { 

x2 = 300; 

y2 = 0; 

ctx.drawImage(myImage, offw, offh, width, height, x2, y2, width, height); 

function update() { 

redraw(); 

frame++; 

if (frame = 22) frame = 0; 

setTimeout( update, 1000/30); 

/script 

/head 

body 

h1HTML Canvas Animations Demo - By Gloomy Fish/h1 

prePlay Animations/pre 

div id="my_painter" 

canvas id="animation_canvas"/canvas 

/div 

/body 

/html

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 拖动效果怎么在手机上实现

html5 拖动效果在手机上实现方法是调用drag和drop一系列函数实现的。

注意:拖拽源在拖拽操作结束将得到dragend事件对象,不管操作成功与否。

举例:

定义可拖放内容

div id="columns"

 div class="column" draggable="true"headerA/header/div

 div class="column" draggable="true"headerB/header/div

 div class="column" draggable="true"headerC/header/div

/div

2、监听拖动事件

可附加大量不同事件以监听整个拖放过程:

dragstart

drag

dragenter

dragleave

dragover

drop

dragend

a.这里是开始拖拽

function handleDragStart(e) {

 this.style.opacity = '0.4';  // this / e.target is the source node.

}

var cols = document.querySelectorAll('#columns .column');

[].forEach.call(cols, function(col) {

 col.addEventListener('dragstart', handleDragStart, false);

});

b.dragenter、dragover 和 dragleave 事件处理程序可用于在拖动过程中提供额外的可视化提示。例如,在拖动期间将鼠标悬停在某一列上方时,其边框可能会变成虚线。这样,用户就能知道这些列也是放置的目标区域。

html5触屏特效代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于html5效果、html5触屏特效代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/31942.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载