/** Event handler for mouse wheel event.
*鼠标滚动事件
*/
var wheel = function(event) {
var delta = 0
if (!event) /* For IE. */
event = window.event
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta / 120
} else if (event.detail) {
/** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail / 3
}
/** If delta is nonzero, handle it.
* Basically, delta is now positive if wheel was scrolled up,
* and negative, if wheel was scrolled down.
*/
if (delta)
handle(delta)
/** Prevent default actions caused by mouse wheel.
* That might be ugly, but we handle scrolls somehow
* anyway, so don't bother here..
*/
if (event.preventDefault)
event.preventDefault()
event.returnValue = false
}
/** Initialization code.
* If you use your own event management code, change it as required.
*/
if (window.addEventListener) {
/** DOMMouseScroll is for mozilla. */
window.addEventListener('DOMMouseScroll', wheel, false)
}
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel
/** This is high-level function.
* It must react to delta being more/less than zero.
*/
var handle = function(delta) {
var random_num = Math.floor((Math.random() * 100) + 50)
if (delta <0) {
// alert("鼠标滑轮向下滚动:" + delta + "次!")// 1
$("btn_next_pic").onclick(random_num)
return
} else {
// alert("鼠标滑轮向上滚动:" + delta + "次!")// -1
$("btn_last_pic").onclick(random_num)
return
}
}
在网页开发中,有些时候我们不想让用户去复制或者粘贴该网页的东西,那么下面的几个方法就非常有用了!
//屏蔽右键菜单document.oncontextmenu = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽粘贴
document.onpaste = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽复制
document.oncopy = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽剪切
document.oncut = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽选中
document.onselectstart = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
} catch (e) {
return false
}
}
网页退出提示的方法:
window.onbeforeunload = function(event){event = event || window.event
event.returnValue = ' '
}
移动端中,屏蔽类似iphone的默认滑动事件用一下方法:
//禁用浏览器的默认滑动事件var preventBehavior = function(e) {
e.preventDefault()
}
// Enable fixed positioning
document.addEventListener("touchmove", preventBehavior, false)
您好!很高兴为您答疑!拼写错误 event.preventDefatult()应该是event.preventDefault() 可以完美运行!
您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)