- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我已经探索了很多方法来使图像在单击元素时出现,例如显示: block 或可见性:可见或 .show()。但是,我遇到的问题是让图像出现在另一个 div 容器中,该容器的类与用户悬停并单击的按钮 ID 相匹配。还有另一个问题使图像在点击后仍然存在。任何建议都会很棒。
HTML
<div id="list">
<div id="button-list">
<ul>
<li id="header1" class ="inactive"><h2>Upper Body</h2></li>
<li id="front-neck" class="upper">Front Neck</li>
<li id="back-neck" class= "upper">Back Neck</li>
<li id="trapezius" class= "upper">Trapezius</li>
<li id="shoulder" class= "upper">Shoulder</li>
<li id="biceps" class= "upper">Bicep</li>
<li id="triceps" class= "upper">Tricep</li>
<li id="forearm" class= "upper">Forearm Extensor</li>
<li id="forearm" class= "upper">Forearm Flexor</li>
<li id="header2" class="inactive"><h2>Lower Body</h2></li>
<li id="hamstring" class="lower">Hamstring</li>
<li id="calf" class="lower">Calf</li>
<li id="it-band" class="lower">IT Band</li>
<li id="adductor" class="lower">Adductor</li>
<li id="quadricep" class="lower">Quadricep</li>
</ul>
</div>
</div>
<div id="anatomy-container">
<img class="front-neck" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/front-neck2.png"/></span>
<img class="back-neck" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Back-Neck-2.png"/></span>
<img class="trapezius" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Traps2.png"/></span>
<img class="shoulder" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Interior-Deltoid2.png"/></span>
<img class="biceps" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Bicep-2.png"/></span>
<img class="triceps" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Tricep2.png"/></span>
<img class="forearm" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/extensor2.png"/></span>
<img class="forearm"src ="http:// m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/FLEXER2.png"/></span>
<img class="hamstring" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Hammy2.png"/></span>
<img class="calf"src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Calf2.png"/></span>
<img class="it-band" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/IT-BAND-2.png"/></span>
<img class="adductor" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Addcutor2.png"/></span>
<img class="quadricep" src ="http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/Quad2.png"/></span>
</div>
<div id="list-container">
<ul id="container">
</ul>
</div>
CSS
body {
padding-top: 80px;
text-align: center;
font-family: monaco, monospace;
}
h1 {
font-size: 30px
}
h2 {
font-size: 20px;
}
ul {
list-style-type: none;
}
#header1, #header2 {
background-color: white;
color: black;
border: 2px solid #4CAF50;
margin: 0 0 10px 0;
}
#header1:hover, #header2:hover, #header1:active, #header2:active {
background-color: #4CAF50;
color: white;
}
.upper, .lower {
background-color: white;
color: black;
border: 2px solid #008CBA;
margin: 0 0 10px 0;
padding: 10px 5px;
}
.upper:hover, .lower:hover {
background-color: #008CBA;
color: white;
}
#list {
position: relative;
}
#button-list{
width: 300px;
}
#highlight{
height: 500px;
width: 500px;
}
#list-container{
border: 2px solid white;
padding:10px;
height: 350px;
width: 200px;
position: relative;
right: 0px;
}
#front-neck{
left: 300px;
position: relative;
bottom: 400px;
}
#tasdf{
height:85px;
width: 200px;
}
JavaScript
var jsonString = {
"stretches": [{
"area": "front-neck",
"name": "front-neck",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/01/fneck1.jpg",
"type": "static"
}, {
"area": "back-neck",
"name": "back-neck",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/IMG_1173.jpg",
"type": "static"
}, {
"area": "side-neck",
"name": "side-neck",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/sideNeck.jpg",
"type": "static"
}, {
"area": "entire-neck",
"name": "neck-rolls",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/neckRollStretch.jpg",
"type": "dynamic"
}, {
"area": "trapezius",
"name": "upper-trapezius",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/trapStretch3.jpg",
"type": "static"
}, {
"area": "trapezius",
"name": "lower-trapezius",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/trapStretch.jpg",
"type": "static"
}, {
"area": "trapezius",
"name": "trapezius",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/trapStretch2.jpg",
"type": "dynamic"
}, {
"area": "shoulder",
"name": "shoulder-raise",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/shoulderRaise.jpg",
"type": "static"
}, {
"area": "shoulder",
"name": "shoudler",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/IMG_1198.jpg",
"type": "static"
}, {
"area": "shoulder",
"name": "arm-circles",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/shoulderCircles.jpg",
"type": "dynamic"
}, {
"area": "shoulder",
"name": "elbow-circles",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/elbowCircles.jpg",
"type": "dynamic"
}, {
"area": "shoulder",
"name": "upward-shoulder",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/upwardShoulder.jpg",
"type": "static"
}, {
"area": "triceps",
"name": "tricep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/tricepStretch.jpg",
"type": "static"
}, {
"area": "triceps",
"name": "tricep-side",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/tricepSideStretch.jpg",
"type": "static"
}, {
"area": "biceps",
"name": "standing-bicep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/bicepStanding.jpg",
"type": "static"
}, {
"area": "biceps",
"name": "seated-bicep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/bicepSeated.jpg",
"type": "static"
}, {
"area": "biceps",
"name": "bicep-side",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/bicepSide.jpg",
"type": "static"
}, {
"area": "forearm",
"name": "forearm-bench",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/forearmTable.jpg",
"type": "static"
}, {
"area": "forearm",
"name": "standing-forearm",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/forearmWall.jpg",
"type": "static"
}, {
"area": "forearm",
"name": "wrist-circles",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/wristCircles.jpg",
"type": "dynamic"
}, {
"area": "it-band",
"name": "seated-glute",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/seatedGlute.jpg",
"type": "static"
}, {
"area": "it-band",
"name": "ankle-to-knee",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/ankleToKneeGlute.jpg",
"type": "static"
}, {
"area": "it-band",
"name": "across-body",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/acrossBody.jpg",
"type": "static"
}, {
"area": "it-band",
"name": "leg-swings",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/legSwings.jpg",
"type": "dynamic"
}, {
"area": "hamstring",
"name": "leg-swings",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/legSwingsHam.jpg",
"type": "dynamic"
}, {
"area": "hamstring",
"name": "hamstring",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/hamstring.jpg",
"type": "static"
}, {
"area": "hamstring",
"name": "walking-kicks",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/hamstringWalking.jpg",
"type": "dynamic"
}, {
"area": "hamstring",
"name": "lying-hamstring",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/IMG_1217.jpg",
"type": "static"
}, {
"area": "hamstring",
"name": "leg-up-hamstring",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/legUpHamstring.jpg",
"type": "dynamic"
}, {
"area": "calf",
"name": "ankle-circles",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/ankleCircles.jpg",
"type": "dynamic"
}, {
"area": "calf",
"name": "calf-wall",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/wallCalf.jpg",
"type": "static"
}, {
"area": "calf",
"name": "seated-calf",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/seatedCalf.jpg",
"type": "static"
}, {
"area": "calf",
"name": "stair-calf",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/stairCalf.jpg",
"type": "static"
}, {
"area": "adductor",
"name": "butterly",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/butterflyAdductor.jpg",
"type": "static"
}, {
"area": "adductor",
"name": "standing-groin",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/standingAdductor.jpg",
"type": "static"
}, {
"area": "adductor",
"name": "leg-swings",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/legSwings.jpg",
"type": "dynamic"
}, {
"area": "adductor",
"name": "sumo",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/sumoAdductor.jpg",
"type": "dynamic"
}, {
"area": "quadricep",
"name": "kneeling-quadricep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/kneelingQuad-1.jpg",
"type": "static"
}, {
"area": "quadricep",
"name": "lying-quadricep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/lyingQuad.jpg",
"type": "static"
}, {
"area": "quadricep",
"name": "bench-quadricep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/benchQuad.jpg",
"type": "static"
}, {
"area": "quadricep",
"name": "scorpion",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/scorpionQuad.jpg",
"type": "dynamic"
}, {
"area": "quadricep",
"name": "sitting-quadricep",
"pic": "http://m68.siteground.biz/~stretc22/wp-content/uploads/2016/07/sittingQuadricep.jpg",
"type": "static"
}]
}
$(function() {
//THIS IS WHERE I INSERTED THE FUNCTION
$("#anatomy-container img").hide();
$('li').on("click,hover", "#button-list li", function() {
imgClass = $(this).attr('id');
$("#anatomy-container img").hide(); // hide all images
$("#anatomy-container ." + imgClass).show(); //show only image that
});
$("li.upper").hide();
$("li.lower").hide();
$("#header1").on('click', function() {
$("li.upper").slideToggle();
var buttonState = $("li#header1").attr("class");
if (buttonState == "inactive") {
$("li#header1").removeClass("inactive");
$("li#header1").addClass("active");
$(this).css({
"background": "#4CAF50",
"color": "white"
});
} else {
$("li#header1").removeClass("active");
$("li#header1").addClass("inactive");
$(this).css({
"background": "white",
"color": "black"
});
}
});
$("#header2").click(function() {
$("li.lower").slideToggle();
var buttonState = $("li#header2").attr("class");
if (buttonState == "inactive") {
$("li#header2").removeClass("inactive");
$("li#header2").addClass("active");
$(this).css({
"background": "#4CAF50",
"color": "white"
});
} else {
$("li#header2").removeClass("active");
$("li#header2").addClass("inactive");
$(this).css({
"background": "white",
"color": "black"
});
}
});
$("li.upper").on("click", function() {
var buttonState = $(this).attr("class");
if (buttonState == "upper inactive") {
$(this).removeClass("upper inactive");
$(this).addClass("upper active");
$(this).css({
"background": "#008CBA",
"color": "white"
});
} else {
$(this).removeClass("upper active");
$(this).addClass("upper inactive");
$(this).css({
"background": "white",
"color": "black"
});
}
});
$("li.lower").on("click", function() {
var buttonState = $(this).attr("class");
if (buttonState == "lower inactive") {
$(this).removeClass("lower inactive");
$(this).addClass("lower active");
$(this).css({
"background": "#008CBA",
"color": "white"
});
} else {
$(this).removeClass("lower active");
$(this).addClass("lower inactive");
$(this).css({
"background": "white",
"color": "black"
});
}
});
//THIS IS THE AREA I'M TRYING TO FIX!!!
var myData = jsonString;
var newContent = '';
var selected = null;
$('li').click(function(e) {
e.preventDefault();
selected = $(this).attr("id");
newContent = "";
/** Perhaps a quite different json structure could remove the for loop **/
for (var i = 0; i < myData.stretches.length; i++) {
if (selected == myData.stretches[i].area) {
newContent += '<li id = "' + selected + '-img" class = "' + myData.stretches[i].area + '">';
newContent += '<a href="' + myData.stretches[i].ref + '">'; /** ref is not defined in JSON **/
newContent += '<img src="' + myData.stretches[i].pic + '">';
//newContent += '<p "'+responseObject.stretches[i].name+'">';
newContent += '</a> + </li>';
}
}
console.log(newContent);
$('#container').html(newContent);
});
});
最佳答案
您可以使用 jQuery 轻松完成。正如您在问题中所描述的那样,您有一个按钮列表和与该按钮对应的图像。
$(function() {
$(document).on("click", "#button-list li", function() {
imgClass = $(this).attr('id');
$("#anatomy-container img").hide(); // hide all images
$("#anatomy-container ." + imgClass).show(); //show only image that class match with button id
});
$(document).on("mouseover", "#button-list li", function() {
imgClass = $(this).attr('id');
$("#anatomy-container img").hide(); // hide all images
$("#anatomy-container ." + imgClass).show(); //show only image that class match with button id
});
});
希望对您有所帮助。
关于javascript - 使 <img> 元素出现在悬停时并保持在与被点击按钮的相同 ID 相对应的点击上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38665110/
我的应用程序包含两部分:网络部分和 GUI。它的工作方式有点像浏览器 - 用户从服务器请求一些信息,服务器发回一些代表某些 View 的数据,然后 GUI 显示它。 现在我已经将网络部分实现为一项服务
给定表达式字符串exp,编写程序检查exp中“{”、“}”、“(”、“)”、“[”、“]的对和顺序是否正确。 package main import ( "fmt" stack "gi
我想要一个简单的脚本在后台保持运行。目前看起来像这样: import keyboard while True: keyboard.wait('q') keyboard.send('ct
我维护着许多 RedHat Enterprise Linux(7 台和 8 台)服务器(>100 台),其中包含不同的应用程序。为了保持理智,我当然会使用 Ansible 等工具,更重要的是,公共(p
我有一个 winforms 应用程序,它在网络服务请求期间被锁定 我已经尝试使用 doEvents 来保持应用程序解锁,但它仍然不够响应, 我怎样才能绕过这个锁定,让应用程序始终响应? 最佳答案 最好
我正在努力在我的项目中获得并保持领先的 0。以下是当前相关的代码: Dim jobNum As String jobNum = Left(r1.Cells(1, 1), 6) r2.Cells(1
我正在尝试在我的 Canvas 中定位元素相对于我的背景。 窗口被重新调整大小,保持纵横比。 背景随着窗口大小而拉伸(stretch)。 问题是一旦重新调整窗口大小,元素位置就会不正确。如果窗口的大小
一直在玩弄 Hibernate 和 PostgreSQL,试图让它按预期工作。 但是由于某种原因,当我尝试将具有@OneToMany 关系的对象与集合中的多个项目保持一致时,除了第一个项目之外,所有项
我想将某些东西提交到 github 存储库,但我(显然)没有任何权利这样做。我对那个 repo 做了一个分支,提交了我的更改并提交了一个 pull-request。 现在,问题是过了一段时间其他人已经
这是一个初学者问题,我仍在考虑“在 OOP 中”,所以如果我错过了手册中的答案或者答案很明显,我深表歉意。 假设我们有一个抽象类型, abstract type My_Abstract_type en
我们正在开展的一些项目在 jQuery 1.4.2 或更早版本中有着深厚的根基,介于缺乏最新版本的性能优势(或语法糖)、使用现已弃用的方法的耻辱以及部署一个积极维护的库的 3 年以上旧版本,升级现在迫
我看到在FMDB 2.0中,作者为线程添加了FMDatabaseQueue。例子是: // First, make your queue. FMDatabaseQueue *queue = [FMDa
我在 NSScrollView 中有一个 NSTableView。 NSTableView 的内容是通过绑定(bind)到 NSArrayController 来提供的,而 NSArrayContro
我在 TreeView 上有一个节点,我手动填充该节点并希望保持排序。通过用户交互,TreeViewItem 上的标题可能会更改,它们应该移动到列表中的适当位置。 我遍历一个 foreach,创建多个
我从主 NSWindow 打开一个 NSWindow。 DropHereWindowController *dropHereWindowController = [[DropHereWindowCon
我需要放置一个 form 3 按钮,当我单击该按钮时,将其显示为按下,其他按钮向上,当我单击另一个按钮时,它应该为“向下”,其他按钮应为“向上” 最佳答案 所有按钮的属性“Groupindex”必须设
我有一个使用 AnyEvent::MQTT 订阅消息队列的 perl 脚本。 目前我想要它做的就是在收到消息时打印出来。我对 perl 完全陌生,所以我正在使用它附带的演示代码,其中包括将 STDIN
如何在 .NET 应用程序中保持 TreeView 控件的滚动位置?例如,我有一个树形 View 控件,并经历了一个向其添加各种节点的过程,并将它们固定在底部。在此过程中,我可以滚动浏览 TreeVi
我维护了大量的 vbscripts,用于在我的网络上执行各种启动脚本,并且有一些我在几乎所有脚本中使用的函数。 除了复制和粘贴之外,有没有人对我如何创建可重用 vbscript 代码库有建议。我并不反
我有一些关于 Azure 自托管的问题。 假设用户 Alex 在物理机 M 上设置了 Windows 自托管代理。当 Alex 注销且计算机进入休眠状态时,代理将脱机。现在,当 Bob 登录同一台计算
我是一名优秀的程序员,十分优秀!