- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经构建了一个小的 bootstrap 3 缩略图文本和 img 操作,现在我有一个关于如何在页面加载时激活它的问题,具体来说我希望 #anime1
在加载时激活页面加载。
看看这个 manipulation例子。您会看到我在那里显示了一堆缩略图,但是当您与操作交互时,它会显示您需要查看的所选 navbar
标题的所有内容。
那么我怎样才能在页面加载时激活它呢?
$(function(){
$('#anime1').click(function(){
$('.column').each(function(){
$( this ).hide( 500 );
});
$('.columns').each(function(){
$( this ).show( 500 );
$('#col1 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col1 h3').text('Grouting!');
$('#col1 p:first').text('Grouting retention text will be displayed here!');
$('#col2 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col2 h3').text('Grouting!');
$('#col2 p:first').text('Grouting retention text will be displayed here!');
$('#col3 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col3 h3').text('Grouting!');
$('#col3 p:first').text('Grouting retention text will be displayed here!');
$('#col4 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col4 h3').text('Grouting!');
$('#col4 p:first').text('Grouting retention text will be displayed here!');
$('#col5 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col5 h3').text('Grouting!');
$('#col5 p:first').text('Grouting retention text will be displayed here!');
$('#col6 img').attr('src', 'img/lazy1.png').prepend('background-image', 'url(img/lazy.png)');
$('#col6 h3').text('Grouting!');
$('#col6 p:first').text('Grouting retention text will be displayed here!');
});
});
$('#anime2').click(function(){
$('.columns').hide( 500 );
$('.column').hide( 500 );
});
$('#anime2').click(function(){
$('.col4').show( 500 );
$('#col4 img').attr('src', 'img/lazy0.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col4 h3').text('Ground Improvements!');
$('#col4 p:first').text('Ground Improvements text will be displayed here!');
});
$('#anime3').click(function(){
$('.column').each(function(){
$( this ).show( 500 );
});
$('.columns').each(function(){
$( this ).show( 500 );
});
$('#col1 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col1 h3').text('Earth Retention!');
$('#col1 p:first').text('Earth Retention retention text will be displayed here!');
$('#col2 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col2 h3').text('Earth Retention!');
$('#col2 p:first').text('Earth Retention retention text will be displayed here!');
$('#col3 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col3 h3').text('Earth Retention!');
$('#col3 p:first').text('Earth Retention retention text will be displayed here!');
$('#col4 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col4 h3').text('Earth Retention!');
$('#col4 p:first').text('Earth Retention retention text will be displayed here!');
$('#col5 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col5 h3').text('Earth Retention!');
$('#col5 p:first').text('Earth Retention retention text will be displayed here!');
$('#col6 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col6 h3').text('Earth Retention!');
$('#col6 p:first').text('Earth Retention retention text will be displayed here!');
$('#col7 img').attr('src', 'img/lazy1.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col7 h3').text('Earth Retention!');
$('#col7 p:first').text('Earth Retention retention text will be displayed here!');
$('#col8').hide( 500 );
});
$('#anime4').click(function(){
$('.column').each(function(){
$( this ).show( 500 );
});
$('.columns').each(function(){
$( this ).show( 500 );
});
$('#col1 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col1 h3').text('Structural Support!');
$('#col1 p:first').text('Structural Support text will be displayed here!');
$('#col2 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col2 h3').text('Structural Support!');
$('#col2 p:first').text('Structural Support text will be displayed here!');
$('#col3 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col3 h3').text('Structural Support!');
$('#col3 p:first').text('Structural Support text will be displayed here!');
$('#col4 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col4 h3').text('Structural Support!');
$('#col4 p:first').text('Structural Support text will be displayed here!');
$('#col5 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col5 h3').text('Structural Support!');
$('#col5 p:first').text('Structural Support text will be displayed here!');
$('#col6 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col6 h3').text('Structural Support!');
$('#col6 p:first').text('Structural Support text will be displayed here!');
$('#col7 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col7 h3').text('Structural Support!');
$('#col7 p:first').text('Structural Support text will be displayed here!');
$('#col8 img').attr('src', 'img/lazy.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col8 h3').text('Structural Support!');
$('#col8 p:first').text('Structural Support text will be displayed here!');
});
$('#anime5').click(function(){
$('.column').hide( 500 );
$('.columns').hide( 500 );
});
$('#anime5').click(function(){
$('.col4').show( 500 );
$('#col4 img').attr('src', 'img/lazy0.jpeg').prepend('background-image', 'url(img/lazy.png)');
$('#col4 h3').text('Additional Technologies!');
$('#col4 p:first').text('Additional Technologies text will be displayed here!');
});
});
缩略图:
<div class="row">
<div class=" col-xs-12 col-sm-12 col-md-8 col-md-offset-2 col-lg-12">
<ul class="nav nav-pills">
<li role="presentation"><a id="anime1" href="#">Grouting</a></li>
<li role="presentation"><a id="anime2" href="#">Ground Improvements</a></li>
<li role="presentation"><a id="anime3" href="#">Earth Retention</a></li>
<li role="presentation"><a id="anime4" href="#">Structural Support</a></li>
<li role="presentation"><a id="anime5" href="#">Additional Technologies</a></li>
</ul>
</div>
</div>
<div class="row">
<p style="padding: 10px;"></p>
</div>
<div class="row">
<div id="col1" class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col2" class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end-->
</div>
<div id="col3" class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col4" class="col-xs-2 col-sm-2 col-md-2 col-lg-2 animate_col4">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">Ovo ce da se animira za Additionl technologies.</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col5" class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">Ovaj ce da se animira za Ground Impovements!</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col6" class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col7" class="column col-xs-2 col-sm-2 col-md-2 col-md-offset-4 col-lg-2 col-lg-offset-4">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
<div id="col8" class="column col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="text-center">Text title, label, etc</h3>
<p class="text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div><!--/ caption-end -->
</div><!--/ thumbnail-end -->
</div>
</div><!--/ end thumbnai row -->
最佳答案
将触发器附加到处理程序选择器
$('#anime1').click(function(){
//... all the code you have
});
修订:
$('#anime1').click(function(){
//... all the code you have
}).trigger('click');
编辑:根据评论修改代码。代码审查
请注意,其中有些是偏好,有些可能有点矫枉过正,我将对每项更改进行推理:
基于您的列标记示例:注意此处没有 id。
<div class="columns col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail">
<img class="img-thumbnail img-responsive" src="http://placehold.it/140x100" alt="">
<div class="caption">
<h3 class="thumbnail-head text-center">Text title, label, etc</h3>
<p class="thumbnail-desc text-center">descritpion here</p>
<p><a href="#" class="btn btn-md btn-primary" role="button">Button</a></p>
</div>
</div>
</div>
链接,添加了一些东西:“a”标签的一个类和 data-thing='
,每个都有一个名称。我们将使用这个 thing
按名称定位 JavaScript 对象数组(查找它们)。
<ul class="nav nav-pills">
<li role="presentation"><a id="anime1" class="mylinks" data-thing="grout" href="#">Grouting</a></li>
<li role="presentation"><a id="anime2" class="mylinks" data-thing="ground" href="#">Ground Improvements</a></li>
<li role="presentation"><a id="anime3" class="mylinks" data-thing="earth" href="#">Earth Retention</a></li>
<li role="presentation"><a id="anime4" class="mylinks" data-thing="struct" href="#">Structural Support</a></li>
<li role="presentation"><a id="anime5" class="mylinks" data-thing="tech" href="#">Additional Technologies</a></li>
</ul>
注意这些也可以从对象中注入(inject)。
这是对象。我用“myApp”命名它。在这个对象中你可以看到数据以及我使用的一些函数。请参阅整个内联评论。
// create my namespace, use any preexisting namespace by that name.
var myApp = myApp || {};
将数据添加到我们的命名空间
// This is the actual data object, it has some defaults that I use
myApp.loadObject = {
defaultActiveLink: "grout",
animateHideDelay: 500,
animateShowDelay: 500,
defaultColumnCount: 8,
// array of "things" that we process (by name)
things: [{
name: "grout",// used to lookup
linkText: "Grouting",// link text (if we wanted to inject it)
// array of links in THIS thing - we use these
columnData: [{
"src": 'http://lorempixel.com/140/100/city',
"alt": "City",
"background": 'url(http://lorempixel.com/140/100/city)',
"headtext": 'Grouting0!',
"paragraphtext": 'Grouting 0 retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/city',
"alt": "City",
"background": 'url(http://lorempixel.com/140/100/city)',
"headtext": 'Grouting 1!',
"paragraphtext": 'Grouting1 retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/city',
"alt": "City",
"background": 'url(http://lorempixel.com/140/100/city)',
"headtext": 'Grouting2!',
"paragraphtext": 'Grouting2 retention text will be displayed here!'
}]
}, {
name: "ground",
linkText: "Ground Improvements",
columnData: [{
"src": 'http://lorempixel.com/140/100/nature',
"alt": "Nature",
"background": 'url(http://lorempixel.com/140/100/nature)',
"headtext": 'Ground Improvements!',
"paragraphtext": 'Ground 1 retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/nature',
"alt": "Nature",
"background": 'url(http://lorempixel.com/140/100/nature)',
"headtext": 'Ground Improvements2!',
"paragraphtext": 'Improvements 2 retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/nature',
"alt": "Nature",
"background": 'url(http://lorempixel.com/140/100/nature)',
"headtext": 'Ground Improvements3!',
"paragraphtext": 'Ground 3 Improvements retention text will be displayed here!'
}]
}, {
name: "earth",
linkText: "Earth Retention",
columnData: [{
"src": 'http://lorempixel.com/140/100/abstract',
"alt": "Abstract",
"background": 'url(http://lorempixel.com/140/100/abstract)',
"headtext": 'Earth1!',
"paragraphtext": 'Earth text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/abstract',
"alt": "Abstract",
"background": 'url(http://lorempixel.com/140/100/abstract)',
"headtext": 'Mother Earth!',
"paragraphtext": 'Mother Earth text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/abstract',
"alt": "Abstract",
"background": 'url(http://lorempixel.com/140/100/abstract)',
"headtext": 'Earthy!',
"paragraphtext": 'Earthy retention text will be displayed here!'
}]
}, {
name: "struct",
linkText: "Structural Support",
columnData: [{
"src": 'http://lorempixel.com/140/100/cats',
"alt": "Cats",
"background": 'url(http://lorempixel.com/140/100/cats)',
"headtext": 'Stuctural!',
"paragraphtext": 'Structural retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/cats',
"alt": "Cats",
"background": 'url(http://lorempixel.com/140/100/cats)',
"headtext": 'Struct!',
"paragraphtext": 'Struct retention text will be displayed here!'
}, {
"src": 'http://lorempixel.com/140/100/cats',
"alt": "Cats",
"background": 'url(http://lorempixel.com/140/100/cats)',
"headtext": 'Struct Last!',
"paragraphtext": 'My Struct Last retention text will be displayed here!'
}]
}, {
name: "tech",
linkText: "Additional Technologies",
columnData: [{
"src": 'http://lorempixel.com/140/100/food',
"alt": "Foody",
"background": 'url(http://lorempixel.com/140/100/food)',
"headtext": 'Tech!',
"paragraphtext": 'Tech Tech Tech text will be displayed here!'
}]
}]
};
向我们的命名空间添加一些通用函数:
// some generic functions to process my "object" not all these are used so you could clip it down a bit
myApp.arrayObj = {
indexOf: function(myArray, searchTerm, property) {
for (var i = 0; i < myArray.length; i++) {
if (myArray[i][property] === searchTerm) return i;
}
return -1;
},
indexAllOf: function(myArray, searchTerm, property) {
var ai = [];
for (var i = 0; i < myArray.length; i++) {
if (myArray[i][property] === searchTerm) ai.push(i);
}
return ai;
},
lookup: function(myArray, searchTerm, property, firstOnly) {
var found = [];
var i = myArray.length;
while (i--) {
if (myArray[i][property] === searchTerm) {
found.push(myArray[i]);
if (firstOnly) break; //if only the first
}
}
return found;
},
lookupAll: function(myArray, searchTerm, property) {
return this.lookup(myArray, searchTerm, property, false);
},
remove: function(myArray, searchTerm, property, firstOnly) {
for (var i = myArray.length - 1; i >= 0; i--) {
if (myArray[i][property] === searchTerm) {
myArray.splice(i, 1);
if (firstOnly) break; //if only the first term has to be removed
}
}
}
};
向我们的命名空间添加一些自定义函数(嗯,只有一个...)
// custom functions
myApp.func = {
/* activate the default specified by name */
setDefault: function() {
var activeDefault = myApp.loadObject.defaultActiveLink;
var defaultIndex = myApp.arrayObj.indexOf(myApp.loadObject.things, activeDefault, "name");
defaultIndex = !!activeDefault ? defaultIndex : 0;
$('.nav-pills').find('.mylinks').eq(defaultIndex).trigger('click');
}
};
标准的 jQuery 东西,这也可以是我们调用的自定义函数。这基本上完成了您所有代码所做的:
// process on click, injecting the appropriate text
$('.nav-pills').on('click', '.mylinks', function() {
// hide using the default hide delay in the object
$('.columns').hide(myApp.loadObject.animateHideDelay);
var thingtype = $(this).data('thing');// added to the link
var thing = myApp.arrayObj.lookup(myApp.loadObject.things, thingtype, "name", true);//lookup by name
var columns = $('.columns');// all the columns
// process the links,showing them
$.each(thing[0].columnData, function(index, item) {
// cache to not do multiple DOM searches
var tn = columns.eq(index).find('.thumbnail');
var cap = tn.find('.caption');
tn.find('img.img-thumbnail').attr('src', item.src).attr('alt', item.alt).prepend('background-image', item.background);
cap.find('h3.thumbnail-head').text(item.headtext);
cap.find('p.thumbnail-desc').text(item.paragraphtext);
// show this one
$('.columns').eq(index).show(myApp.loadObject.animateShowDelay);
});
});
$(function() {
// activate the default specified by name
myApp.func.setDefault();
});
关于javascript - 在页面加载时激活 jQuery img 和文本操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36874187/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!