我有一个400px的图像和一个较小的div(宽度并不总是300px,如我的例子).我想将图像居中在div中,如果有溢出,则隐藏它.
注意:我必须保留position:absolute图像.我正在使用css-transitions,如果我使用position:relative,我的图像会有点震动(https://web.archive.org/web/20120528225923/http://ta6.maxplus.be:8888/).
jsfiddle http://jsfiddle.net/wjw83/1/
如何使用动画切换div的宽度?
HTML:
<div id="toggle-button"></div>
<div id="toggle"></div>?
Run Code Online (Sandbox Code Playgroud)
CSS:
#toggle{
height:200px;
width:200px;
background:red;
}
#toggle-button{
height:20px;
width:20px;
background:blue;
}
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(document).ready( function(){
$('#toggle-button').click( function() {
$('#toggle').toggle(function() {
$('#toggle').animate({width:"200px"});
}, function() {
$('#toggle').animate({width:"300px"});
});
});
});?
Run Code Online (Sandbox Code Playgroud)
不起作用的示例:http: //jsfiddle.net/ZfHZV/1/
编辑:我的目标是在点击蓝色div时更改宽度
HTML:
<div id="parent">
<div class="child"></div>
<div class="child"><p>Div with content<p></div>
<div class="child"><img scr="pic.png" alt="Div with picture" /></div>
</div>
Run Code Online (Sandbox Code Playgroud)
结果我想:
<div id="parent">
<div class="child"></div>
<div class="child"><h1>title</h1><p>Div with content<p></div>
<div class="child"><h1>title</h1><img scr="pic.png" alt="Div with picture" /></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的jQuery代码:
$(".child").each(function() {
if ($(this).html != '')
$(this).prepend('<h1>title</h1>');
});
Run Code Online (Sandbox Code Playgroud)
我的jQuery代码的结果:
<div id="parent">
<div class="child"><h1>title</h1></div>
<div class="child"><h1>title</h1><p>Div with content<p></div>
<div class="child"><h1>title</h1><img scr="pic.png" alt="Div with picture" /></div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我只想为某个不是空的类的每个div添加一个标题.
可能重复:
在分页期间保留url参数
我想用php向当前url添加一个参数,但是如何知道url是否已包含参数?
例:
foobar.com/foo/bar/index.php => foobar.com/foo/bar/index.php?myparameter=5 foobar.com/index.php?foo=7 => foobar.com/index.php?foo = 7&myparameter = 5
主要问题是我不知道是否需要添加"?".
我的代码(在某个地方找到它,但它不起作用):
<?php if(/?/.test(self.location.href)){ //if url contains ?
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]&myparameter=5";
} else {
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]?myparameter=5";
}?>
Run Code Online (Sandbox Code Playgroud) 我有2个div,一个是可见的,一个不是.我想通过单击链接来切换可见性,但是当我第二次切换时,我的第一个div不会出现.
HTML:
<div class="search-extra">
<a href="#" id="toggle-to-advanced">Toggle to red</a>
</div>
<div class="search-advanced">
<a href="#" id="toggle-to-normal">Toggle to black</a>
</div>?
Run Code Online (Sandbox Code Playgroud)
CSS:
.search-advanced{display:none;}
Run Code Online (Sandbox Code Playgroud)
jQuery的:
jQuery('#toggle-to-normal').click(function(e){
e.preventDefault();
jQuery('.search-advanced').slideUp('normal').queue( function(){
jQuery('.search-extra').slideDown('normal');
});
});
jQuery('#toggle-to-advanced').click(function(e){
e.preventDefault();
jQuery('.search-extra').slideUp('normal').queue( function(){
jQuery('.search-advanced').slideDown('normal');
});
});?
Run Code Online (Sandbox Code Playgroud)
演示: