gpt4 book ai didi

javascript - 难以更改 UL 内的 IMG Src,点击时已存在点击功能

转载 作者:行者123 更新时间:2023-11-28 00:27:14 24 4
gpt4 key购买 nike

您可以在此处查看示例: https://blennd.com/

向下滚动到“我们做什么”。

Blendd 上有 4 个 svg 图像,其中 1 个默认处于事件状态。当您单击下一个图像时,一组新文本会出现在包含所有图像的容器下方。

这正是我要实现的功能。我又去codepen做了实验。这是我想出的:

https://codepen.io/Lancewalker/pen/zepjXr

阻碍我的步骤是在单击每个 img 时更改 img src。除此之外,我想要的全部功能都在那里。

如果除了拥有 img src 之外还有其他更好的方法,我也愿意接受。

 // tabbed content
// http://www.entheosweb.com/tutorials/css/tabs.asp
$(".tab_content").hide();
$(".tab_content:first").show();

/* if in tab mode */
$("ul.tabs li").click(function() {

$(".tab_content").hide();
var activeTab = $(this).attr("rel");
$("#"+activeTab).fadeIn();

$("ul.tabs li").removeClass("active");
$(this).addClass("active");

$(".tab_drawer_heading").removeClass("d_active");
$(".tab_drawer_heading[rel^='"+activeTab+"']").addClass("d_active");

});
/* if in drawer mode */
$(".tab_drawer_heading").click(function() {

$(".tab_content").hide();
var d_activeTab = $(this).attr("rel");
$("#"+d_activeTab).fadeIn();

$(".tab_drawer_heading").removeClass("d_active");
$(this).addClass("d_active");

$("ul.tabs li").removeClass("active");
$("ul.tabs li[rel^='"+d_activeTab+"']").addClass("active");
});


/* Extra class "tab_last"
to add border to right side
of last tab */
$('ul.tabs li').last().addClass("tab_last");
body {
background-color: #333;
color: #fff;
}

h2 {
text-transform: uppercase;
font-size: 3rem;
}
ul.tabs {
margin: 0;
padding: 0;
float: left;
list-style: none;
height: 232px;
border-bottom: 1px solid #333;
width: 100%;
display: flex;
justify-content: center;
}

ul.tabs img{
width: 200px;
height: 200px;
}

ul.tabs li {
float: left;
margin: 0;
cursor: pointer;
padding: 0px 0px;
margin: 0 -20px;
height: 232px;
line-height: 31px;

color: #ccc;
overflow: hidden;
position: relative;
}


ul.tabs li.active {
color: #333;
display: block;
}

.tab_container {
padding-top: 75px;
clear: both;
float: left;
width: 100%;
overflow: auto;
display: flex;
justify-content: center;
text-align: center;
}

.tab_content {
padding: 20px;
display: none;
}

.tab_drawer_heading { display: none; }

@media screen and (max-width: 480px) {
.tabs {
display: none;
}
.tab_drawer_heading {
background-color: #ccc;
color: #fff;
border-top: 1px solid #333;
margin: 0;
padding: 5px 20px;
display: block;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.d_active {
background-color: #666;
color: #fff;
}
}

#img2 {
margin-top: 90px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

<ul class="tabs">
<li class="active" rel="tab1"><img src="https://i.imgur.com/qDiv1eb.png"></li>
<li rel="tab2" id="img2"><img src="https://i.imgur.com/Yu991zv.png"></li>
<li rel="tab3"><img src="https://i.imgur.com/JYrxfHv.png"></li>
<li rel="tab4" id="img2"><img src="https://i.imgur.com/1ub27In.png"></li>
<li rel="tab5"><img src="https://i.imgur.com/7Bi6rVL.png"></li>

</ul>

<div class="tab_container">
<h3 class="d_active tab_drawer_heading" rel="tab1">Tab 1</h3>
<div id="tab1" class="tab_content">
<h2>Tab 1 content</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac metus augue.</p>
</div>
<!-- #tab1 -->
<h3 class="tab_drawer_heading" rel="tab2">Tab 2</h3>
<div id="tab2" class="tab_content">
<h2>Tab 2 content</h2>
<p>Nunc dui velit, scelerisque eu placerat volutpat, dapibus eu nisi. Vivamus eleifend vestibulum odio non vulputate.</p>
</div>
<!-- #tab2 -->
<h3 class="tab_drawer_heading" rel="tab3">Tab 3</h3>
<div id="tab3" class="tab_content">
<h2>Tab 3 content</h2>
<p>Nulla eleifend felis vitae velit tristique imperdiet. Etiam nec imperdiet elit. Pellentesque sem lorem, scelerisque sed facilisis sed, vestibulum sit amet eros.</p>
</div>
<!-- #tab3 -->
<h3 class="tab_drawer_heading" rel="tab4">Tab 4</h3>
<div id="tab4" class="tab_content">
<h2>Tab 4 content</h2>
<p>Integer ultrices lacus sit amet lorem viverra consequat. Vivamus lacinia interdum sapien non faucibus. Maecenas bibendum, lectus at ultrices viverra, elit magna egestas magna, a adipiscing mauris justo nec eros.</p>
</div>
<!-- #tab4 -->
<h3 class="tab_drawer_heading" rel="tab5">Tab 5</h3>
<div id="tab5" class="tab_content">
<h2>Tab 5 content</h2>
<p>Integer ultrices lacus sit amet lorem viverra consequat. Vivamus lacinia interdum sapien non faucibus. Maecenas bibendum, lectus at ultrices viverra, elit magna egestas magna, a adipiscing mauris justo nec eros.</p>
</div>
<!-- #tab5 -->
</div>
<!-- .tab_container -->
</div>

最佳答案

这可以通过两个 <img> 来实现在选项卡和一些 CSS 代码中。

Note: Active and Inactive images are different here, you can change accordingly.

这是添加的 CSS。

ul.tabs li.active > img.img-inactive {
display: none;
}
ul.tabs li.active > img.img-active {
display: block;
}
ul.tabs li > img.img-active {
display: none;
}

// tabbed content
// http://www.entheosweb.com/tutorials/css/tabs.asp
$(".tab_content").hide();
$(".tab_content:first").show();

/* if in tab mode */
$("ul.tabs li").click(function() {

$(".tab_content").hide();
var activeTab = $(this).attr("rel");
$("#"+activeTab).fadeIn();

$("ul.tabs li").removeClass("active");
$(this).addClass("active");

$(".tab_drawer_heading").removeClass("d_active");
$(".tab_drawer_heading[rel^='"+activeTab+"']").addClass("d_active");

});
/* if in drawer mode */
$(".tab_drawer_heading").click(function() {

$(".tab_content").hide();
var d_activeTab = $(this).attr("rel");
$("#"+d_activeTab).fadeIn();

$(".tab_drawer_heading").removeClass("d_active");
$(this).addClass("d_active");

$("ul.tabs li").removeClass("active");
$("ul.tabs li[rel^='"+d_activeTab+"']").addClass("active");
});


/* Extra class "tab_last"
to add border to right side
of last tab */
$('ul.tabs li').last().addClass("tab_last");
/*************New CSS*/
ul.tabs li.active > img.img-inactive {
display: none;
}
ul.tabs li.active > img.img-active {
display: block;
}
ul.tabs li > img.img-active {
display: none;
}
/**********New CSS*/
body {
background-color: #333;
color: #fff;
}

h2 {
text-transform: uppercase;
font-size: 3rem;
}
ul.tabs {
margin: 0;
padding: 0;
float: left;
list-style: none;
height: 232px;
border-bottom: 1px solid #333;
width: 100%;
display: flex;
justify-content: center;
}

ul.tabs img{
width: 200px;
height: 200px;
}

ul.tabs li {
float: left;
margin: 0;
cursor: pointer;
padding: 0px 0px;
margin: 0 -20px;
height: 232px;
line-height: 31px;

color: #ccc;
overflow: hidden;
position: relative;
}


ul.tabs li.active {
color: #333;
display: block;
}

.tab_container {
padding-top: 75px;
clear: both;
float: left;
width: 100%;
overflow: auto;
display: flex;
justify-content: center;
text-align: center;
}

.tab_content {
padding: 20px;
display: none;
}

.tab_drawer_heading { display: none; }

@media screen and (max-width: 480px) {
.tabs {
display: none;
}
.tab_drawer_heading {
background-color: #ccc;
color: #fff;
border-top: 1px solid #333;
margin: 0;
padding: 5px 20px;
display: block;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.d_active {
background-color: #666;
color: #fff;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<ul class="tabs">
<li class="active" rel="tab1">
<img src="https://i.imgur.com/qDiv1eb.png" class="img-active">
<img src="https://i.imgur.com/Yu991zv.png" class="img-inactive">
</li>
<li rel="tab2" id="img2">
<img src="https://i.imgur.com/qDiv1eb.png" class="img-active">
<img src="https://i.imgur.com/Yu991zv.png" class="img-inactive">
</li>

</ul>
<div class="tab_container">
<h3 class="d_active tab_drawer_heading" rel="tab1">Tab 1</h3>
<div id="tab1" class="tab_content">
<h2>Tab 1 content</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac metus augue.</p>
</div>
<!-- #tab1 -->
<h3 class="tab_drawer_heading" rel="tab2">Tab 2</h3>
<div id="tab2" class="tab_content">
<h2>Tab 2 content</h2>
<p>Nunc dui velit, scelerisque eu placerat volutpat, dapibus eu nisi. Vivamus eleifend vestibulum odio non vulputate.</p>
</div>

</div>

关于javascript - 难以更改 UL 内的 IMG Src,点击时已存在点击功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54585907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com