- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个包含 3 张幻灯片的 Accordion 菜单。我需要在悬停时获取最后一个事件类,以便能够将其用于检查条件,以便在鼠标光标离开菜单 div 时保持幻灯片打开。到目前为止,我能够将类附加到每张幻灯片,但它们只检查它们是否在菜单 div 内。有没有办法检查我悬停在上面的唯一一张事件幻灯片?
Codepen
HTML代码
<div class="myMenu">
<ul>
<li class="mySlides slide1"><a class="img1" href="#"></a></li>
<li class="mySlides slide2"><a class="img2" href="#"></a></li>
<li class="mySlides slide3"><a class="img3" href="#"></a></li>
</ul>
</div>
JavaScript
var slide1 = document.querySelector('.slide1');
var slide2 = document.querySelector('.slide2');
var slide3 = document.querySelector('.slide3');
var img1 = document.querySelector('.img1');
var img2 = document.querySelector('.img2');
var img3 = document.querySelector('.img3');
/* */
document.querySelector('.myMenu').addEventListener('mouseout', mouseOutMenu);
function mouseOutMenu() {
if(slide1.classList.contains('insideMenu')) {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
if(slide2.classList.contains('insideMenu')) {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
if(slide3.classList.contains('insideMenu')) {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
}
}
/**************** 1 *******************/
/**********************************************************/
document.querySelector('.slide1').addEventListener('mouseover', mouseOver1);
function mouseOver1() {
slide1.classList.add('insideMenu');
if(slide1.style.width == '298px') {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
} else {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
}
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
document.querySelector('.slide1').addEventListener('mouseout', mouseOut1);
function mouseOut1() {
if(slide1.style.width > '21px') {
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
}
}
/**************** 2 *******************/
/**********************************************************/
document.querySelector('.slide2').addEventListener('mouseover', mouseOver2);
function mouseOver2() {
slide2.classList.add('insideMenu');
if(slide2.style.width == '301px') {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
} else {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
}
// close the rest of slides
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
document.querySelector('.slide2').addEventListener('mouseout', mouseOut2);
function mouseOut2() {
if(slide2.style.width > '21px') {
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
}
}
/**************** 3 *******************/
/**********************************************************/
document.querySelector('.slide3').addEventListener('mouseover', mouseOver3);
function mouseOver3() {
slide3.classList.add('insideMenu');
if(slide3.style.width == '301px') {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
} else {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
}
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
}
document.querySelector('.slide3').addEventListener('mouseout', mouseOut3);
function mouseOut3() {
if(slide3.style.width > '21px') {
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
}
/**********************************************************/
最佳答案
只是对您的代码稍作修改。我希望它能满足您的需求,顺便说一句,这是一个起点:
var slide1 = document.querySelector('.slide1');
var slide2 = document.querySelector('.slide2');
var slide3 = document.querySelector('.slide3');
var img1 = document.querySelector('.img1');
var img2 = document.querySelector('.img2');
var img3 = document.querySelector('.img3');
var timer;
/* */
document.querySelector('.myMenu').addEventListener('mouseout', mouseOutMenu);
function mouseOutMenu() {
if (slide1.classList.contains('insideMenu')) {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
if (slide2.classList.contains('insideMenu')) {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
if (slide3.classList.contains('insideMenu')) {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
}
}
/**************** 1 *******************/
/**********************************************************/
document.querySelector('.slide1').addEventListener('mouseover', mouseOver1);
function mouseOver1() {
pauseTheLoop();
slide1.classList.add('insideMenu');
if (slide1.style.width == '298px') {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
} else {
slide1.style.width = '298px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
}
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
document.querySelector('.slide1').addEventListener('mouseout', mouseOut1);
function mouseOut1() {
if (slide1.style.width > '21px') {
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
}
}
/**************** 2 *******************/
/**********************************************************/
document.querySelector('.slide2').addEventListener('mouseover', mouseOver2);
function mouseOver2() {
pauseTheLoop();
slide2.classList.add('insideMenu');
if (slide2.style.width == '301px') {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
} else {
slide2.style.width = '301px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
}
// close the rest of slides
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
}
document.querySelector('.slide2').addEventListener('mouseout', mouseOut2);
function mouseOut2() {
if (slide2.style.width > '21px') {
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
}
}
/**************** 3 *******************/
/**********************************************************/
document.querySelector('.slide3').addEventListener('mouseover', mouseOver3);
function mouseOver3() {
pauseTheLoop();
slide3.classList.add('insideMenu');
if (slide3.style.width == '301px') {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
} else {
slide3.style.width = '301px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
}
slide2.style.width = '21px';
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
slide1.style.width = '21px';
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
}
document.querySelector('.slide3').addEventListener('mouseout', mouseOut3);
function mouseOut3() {
if (slide3.style.width > '21px') {
slide3.style.width = '21px';
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
/*img3.style.backgroundRepeat = 'no-repeat';*/
}
}
/**********************************************************/
var slideIndex = 0;
carousel();
function carousel() {
var index;
var slides = document.getElementsByClassName('mySlides');
for (index = 0; index < slides.length; index++) {
slides[index].style.width = '21px';
if (slides[0].style.width == '21px') {
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_closed_pnlynb.jpg')";
img1.style.backgroundRepeat = 'no-repeat';
}
if (slides[1].style.width == '21px') {
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_closed_aonaaq.jpg')";
img2.style.backgroundRepeat = 'no-repeat';
}
if (slides[2].style.width == '21px') {
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_closed_tobbqu.jpg')";
img3.style.backgroundRepeat = 'no-repeat';
}
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex - 1].style.width = '301px';
if (slides[0].style.width == '301px') {
slides[0].style.width = '298px'
img1.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/1_open_leszbs.jpg')";
}
if (slides[1].style.width == '301px') {
img2.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/2_open_g8qfff.jpg')";
}
if (slides[2].style.width == '301px') {
img3.style.backgroundImage = "url('https://res.cloudinary.com/dijc9b7wz/image/upload/v1511157235/3_open_gcengd.jpg')";
}
timer = setTimeout(function() {
carousel();
}, 2000);
}
function pauseTheLoop() {
clearTimeout(timer);
console.log('stop loop');
timer = setTimeout(function() {
carousel();
console.log('restart loop');
}, 10000);
}
.myMenu {
position: relative;
width: 420px;
height: 161px;
overflow: hidden;
margin: 35px;
outline:1px solid red;
}
.myMenu ul {
list-style: none;
margin: 0px;
display: block;
}
.myMenu ul li {
float: left;
margin-right:5px;
padding-bottom:2px;
transition: width .3s ease-in-out;
}
.myMenu ul li a {
/*border-right: 1px solid #fff;*/
cursor:pointer;
display:block;
/*overflow:hidden;*/
height: 161px;
margin-left:1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="myMenu">
<ul>
<li class="mySlides slide1">
<a class="img1" href="#"></a>
</li>
<li class="mySlides slide2">
<a class="img2" href="#"></a>
</li>
<li class="mySlides slide3">
<a class="img3" href="#"></a>
</li>
</ul>
</div>
我已经添加了一个对您创建的计时器的控件,这样您就可以在鼠标悬停在幻灯片上时销毁它并停止循环 n 秒。这是代码笔:https://codepen.io/anon/pen/BmYOrZ?editors=1111
关于javascript - 当鼠标光标离开 div 时获取悬停的最后一个事件类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47401791/
我正在尝试为我的网站创建一个功能,允许用户使用 mousemove 和 touchmove 事件水平滚动 div 内容(类似于 Apple AppStore any app Screenshots s
我有固定的侧边栏导航栏,它在悬停时工作,但我想通过单击折叠按钮打开第一个菜单。类似于悬停在菜单 1 上的工作方式。我已经尝试了以下方法。 jsfiddle Demo $(document).on('c
Mouse.Synchronize() 在 .Net 中有什么作用? MSDN 说它“强制鼠标重新同步” 最佳答案 只是我的假设: Stylus 中存在类似的方法类别:Stylus.Synchroni
有没有什么办法可以同时使用鼠标, pygame.mouse.set_visible(False) 已激活。当前鼠标仅在尝试使用时返回右下坐标。需要在隐藏鼠标时能够获得正确的坐标。 在他们的 docum
我有一个缺少数据的数据库。我需要估算数据(我使用的是鼠标),然后根据原始列创建新列(使用估算数据)。我需要使用这些新列进行统计分析。 具体来说,我的参与者使用李克特 7 分量表填写了几份问卷。有些人没
我正在编写一个与电脑交互的机器人。简而言之,我所做的是: -截取屏幕截图- 在此屏幕截图上识别对象(使用 cv2 matchTemplate) -使用找到的位置进行一些鼠标操作(例如:将鼠标指针移动到
我的程序是一个文本游戏,它使用 WindowsForm 上的文本框模拟控制台输出。我试图实现的一个功能是通过单击一个按钮,它将以一定的速度输出到 TextBox,这是通过这种方法实现的 atm: pu
我遇到了一个问题。如果有任何帮助,我将不胜感激。 我正在尝试从玩家位置射击到鼠标点击位置。代码没有给我任何错误,根据我的逻辑,它应该可以工作,但它没有 它创建了项目符号对象,仅此而已。 //Bulle
给定一个带蓝牙的 Windows Mobile 6.1 智能手机,我想将它注册为鼠标。 基本上我现在做的: 使用 Guid {00001124-0000-1000-8000-00805f9b34fb}
我有一个关于在 JavaFX 中实现鼠标拖动事件的正确方法的问题。 我的 playGame() 方法当前使用 onMouseClicked,但这只是一个占位符 理想情况下,我希望“飞盘”沿着鼠标拖动的
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我目前正在使用 Windows 的 RawInput API 来访问键盘和鼠标输入。我有点困惑的一件事是,当我将鼠标注册为 RawInputDevice 时,我无法移动我的 Win32 窗口或使用那里
我想在我的网站浏览器窗口中 move 鼠标,如下所示:www.lmsify.com。我怎样才能做到这一点?(javascript、flash、activex) 问候,丽莎M 最佳答案 他们并没有真正
我想要一个动画。我是后端开发人员,但我必须使用 jquery 创建动画。 动画、背景和元素位置随鼠标移动而变化。 类似于http://www.kennedyandoswald.com/#!/premi
如何将鼠标“锁定”到某个 OpenGL 窗口。有点像在 Minecraft 中是如何完成的。GameDev 是一个更好的询问地点吗? 最佳答案 正如 Robert 在评论中所说,OpenGL 实际上并
我正在尝试实现一个颜色选择器,它从屏幕上各处的像素中获取颜色。为此,我计划使用全局鼠标 Hook 来监听 WM_MOUSEMOVE,以便在鼠标四处移动时更新颜色,并监听鼠标点击以确认 (WM_LBUT
如何使用 Java 和 JNA(Java native 访问)与 Windows API 交互?。我试图通过在鼠标输入流上排队鼠标事件来让鼠标做某事,并且代码有效,因为 SendInput(...)
我想用 C++ 脚本 move 鼠标光标。我在 Parallels 中的 Windows 7 中使用 Visual C++ 2010 Express,并创建了一个控制台应用程序。 我知道 SetCur
我有一些关于 WH_MOUSE 的问题。根据我的阅读,通过将钩子(Hook)放入 DLL 中,它会注入(inject)进程。这是否意味着捕获鼠标也适用于我的桌面、菜单启动等?那么应用程序的标题栏呢?我
如何为多只鼠标显示另一个光标? 我有两个 TMemos,两个可以输入各自 TMemo 的键盘,2 个鼠标,我需要 2 个光标。 如果假设的话,我已经可以检测出哪只鼠标是哪只了。我怎样才能让我自己的光标
我是一名优秀的程序员,十分优秀!