我有一个简单的脚本,使用左箭头和右箭头移动到下一篇和上一篇博文。
var nextEl = document.getElementById("pagination__next__link");
var prevEl = document.getElementById("pagination__prev__link");
document.onkeyup = function(e) {
if (nextEl !== null) {
if (e.keyCode === 37) {
window.location.href = nextEl.getAttribute('href');
}
}
if (prevEl !== null) {
if (e.keyCode === 39) {
window.location.href = prevEl.getAttribute('href');
}
}
return false;
};
Run Code Online (Sandbox Code Playgroud)
但当我有文字input或textarea焦点集中时它也有效。聚焦时禁用键盘快捷键的最佳方法是什么?
谢谢!
有gulp-requirejs插件,但它被列入黑名单,并显示以下消息:" 直接使用require.js模块".
文档非常稀疏,我如何最好地将它与Gulp构建任务结合使用?
在文档中有一个例子:
var requirejs = require('requirejs');
var config = {
baseUrl: '../appDir/scripts',
name: 'main',
out: '../build/main-built.js'
};
requirejs.optimize(config, function (buildResponse) {
//buildResponse is just a text output of the modules
//included. Load the built file for the contents.
//Use config.out to get the optimized file contents.
var contents = fs.readFileSync(config.out, 'utf8');
}, function(err) {
//optimization err callback
});
Run Code Online (Sandbox Code Playgroud)
但这对我没什么帮助......这是我最好的尝试:
var gulp = require('gulp'),
r = require('requirejs').optimize;
var config2 = { …Run Code Online (Sandbox Code Playgroud) 我正在使用Hammer.js来寻找水平平移手势,我设计了一个简单的功能,可以在向左或向右平移时单击按钮.它工作正常,除了垂直滚动在触摸设备上没有做任何事情,或者它真的很奇怪和奇怪.
这是功能:
var panelSliderPan = function() {
// Pan options
myOptions = {
// possible option
};
var myElement = document.querySelector('.scroll__inner'),
mc = new Hammer.Manager(myElement);
mc.add(new Hammer.Pan(myOptions));
// Pan control
var panIt = function(e) {
// I'm checking the direction here, my common sense says it shouldn't
// affect the vertical gestures, but it blocks them somehow
// 2 means it's left pan
if (e.direction === 2) {
$('.controls__btn--next').click();
// 4 == right
} else if (e.direction === 4) { …Run Code Online (Sandbox Code Playgroud) 我试图将延迟添加到一个简单的下拉菜单中。使用以下代码,我得到了延迟,但种类错误。当我非常快地将鼠标移到菜单上时,它会延迟它,但在300ms之后仍会打开它。正确的做法是,当鼠标悬停在菜单上300ms时(与离开菜单时一样)打开菜单。
$('#menu-item-1226:not(.parent-pageid-1225 #menu-item-1226)').hover(function(){
var menu = this;
setTimeout(function(){
$(menu).find('ul').slideToggle(100);
}, 300);
});
Run Code Online (Sandbox Code Playgroud)
我是否必须以stop某种方式做到这一点?或者什么是正确的方法?
提前致谢