hi everyone i want the images to expand and collapse in jquery
so here is my code ...
<div id="expand_image" style="border-top:1px solid #000">
<img src="http://www.hurriyet.com.tr/_np/7181/17287181.jpg" hspace=5/>
</div>
<div id="expand_image">
<img src="http://www.hurriyet.com.tr/_np/2790/17282790.jpg" hspace=5 />
</div>
<div id="expand_image">
<img src="http://www.hurriyet.com.tr/_np/6751/17286751.jpg" hspace=5 />
</div >
<div id="expand_image">
<img src="http://www.hurriyet.com.tr/_np/7203/17287203.jpg" hspace=5 />
</div>
</div>
The below is css style
#expand_image { overflow:hidden; float:left; height:100px; margin:0 5px; border-bottom: 1px solid #000; cursor:pointer; }
jquery code is as given below...
$(function() {
$("#expand_image ").click(function() {
var imgwidth = this.width;
var imgheight = this.height;
$a=300;
$b=this.height;
alert(this.width + 'x' + this.height);
if ($a==$b )
{
alert('300');
$(this).css('height', '100');
$(this).css('width', '580');
}
else
{
alert('100');
$(this).css('height', '300');
$(this).css('width', '580');
}
});
});
so what i want is ..when i click on one image it should expand and others should collapse..
while if i click on expanded image it should collapse
so i was trying to get the image heights
so if its 300 then collapse else expand
but the output of
alert(this.width + '-' + this.height);
is :
anyone knows about this?
thanks in advance..:)
Never use same ID
On your HTML, you are using <div id="expand_image" which will cause problem to find the element.
Refer LIVE DEMO
HTML:
<div class="expand_image" style="border-top:1px solid #000">
<img src="http://www.hurriyet.com.tr/_np/7181/17287181.jpg" hspace=5/>
</div>
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/2790/17282790.jpg" hspace=5 />
</div>
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/6751/17286751.jpg" hspace=5 />
</div >
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/7203/17287203.jpg" hspace=5 />
</div>
JS:
$(function() {
$(".expand_image").click(function() {
$(this).css({
'height':'300',
'width':'580'
});
$(".expand_image").not(this).css({
'height':'100',
'width':'580'
});
});
});
CSS:
.expand_image {
overflow:hidden;
float:left;
height:100px;
margin:0 5px;
border-bottom: 1px solid #000;
cursor:pointer;
}
height and width are functions, so you need to call height() instead of height (notice the braces), try this instead:
alert(this.width() + '-' + this.height());
First put your divs in a wrapper then reference them by class instead of id...since you have the same id's which will avoid collisions:
<div id="wrapper">
<div class="expand_image" style="border-top:1px solid #000">
<img src="http://www.hurriyet.com.tr/_np/7181/17287181.jpg" hspace=5/>
</div>
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/2790/17282790.jpg" hspace=5 />
</div>
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/6751/17286751.jpg" hspace=5 />
</div >
<div class="expand_image">
<img src="http://www.hurriyet.com.tr/_np/7203/17287203.jpg" hspace=5 />
</div>
</div>
by having it in a div wrapper you do not have to initiate every instance of the expand_image class so this code is will perform better:
$("#wrapper").on("click", ".expand_image", function () {
if ($(this).height() == 300) {
$(this).css('height', '100');
} else {
$(".expand_image").css('height', '100');
$(this).css('height', '300');
}
});
Update your CSS by changing #expand_image to .expand_image
.expand_image { overflow:hidden; float:left; height:100px; margin:0 5px; border-bottom: 1px solid #000; cursor:pointer; }
and it will work! HERE IS A JSFIDDLE EXAMPLE
Related
I have two elements in a photo upload cropping tool which I am trying to bring in center and side by side.
.imageuploadcropcontainer {
text-align:center;
margin: 0 auto;
}
<div class="imageuploadcropcontainer">
<img src="<?php echo $upload_path.$large_image_name.$_SESSION['user_file_ext'];?>" style="margin-right: 10px;" id="thumbnail" alt="Create Thumbnail" />
<div style="border:1px #e5e5e5 solid; position:relative; overflow:hidden; width:<?php echo $thumb_width;?>px; height:<?php echo $thumb_height;?>px;">
<img src="<?php echo $upload_path.$large_image_name.$_SESSION['user_file_ext'];?>" style="position: relative;" alt="Thumbnail Preview" />
</div>
Image source with alt="Create Thumbnail is already in center, but image source alt="Thumbnail Preview" is on the left side of the page. If I put this element on float right then it goes to extreme right side of page, I do not want to use margins to set it, otherwise that is working.
.imageuploadcropcontainer {
margin: 0 auto;
width: 300px;
}
.imageuploadcropcontainer #thumbnail,
.imageuploadcropcontainer .hello {
width: 50%;
float: left;
}
.imageuploadcropcontainer:after {
content: '';
display: block;
clear: both;
}
<div class="imageuploadcropcontainer">
<img src="" id="thumbnail" alt="Create Thumbnail" />
<div class="hello" >
<img src="#" alt="Thumbnail Preview" />
</div>
Updated after comment question:
can i manipulate the space between the two
Sure you can, depending on what you exactly want. Right now there is no space between the two. See the green borders while running the next snippet.
.imageuploadcropcontainer {
margin: 0 auto;
width: 300px;
border: solid 1px orange;
}
.imageuploadcropcontainer #thumbnail,
.imageuploadcropcontainer .hello {
width: calc(50% - 2px); /* 2px is border 1px left + 1px right from each box */
float: left;
border: solid 1px green;
}
.imageuploadcropcontainer:after {
content: '';
display: block;
clear: both;
}
<div class="imageuploadcropcontainer">
<img src="" id="thumbnail" alt="Create Thumbnail" />
<div class="hello" >
<img src="#" alt="Thumbnail Preview" />
</div>
I am newbie in HTML and CSS. I need radiobutton which locates under div. Now there's a div and radiobutton to right of.
<div class="rates">
<? foreach ($rates as $rate) { ?>
<div class="rates-block" <? if ($rate->id % 4 != 1) { ?> style="margin-left: 48px;" <? } ?>>
<img src="/images/aukc_image/<?= $rate->img ?>" class="products-img rate-img" alt="product-1">
</div>
<input class="rate-radio" type="radio" name="radio1" value="<?= $rate->count ?>;<?= $rate->price ?>">
<? } ?>
</div>
There's my CSS for thats classes:
.rates {
margin-top: 19px;
}
.rates-block {
display: inline-block;
background-color: #FFFFFF;
width: 152px;
height: 154px;
border: 1px solid rgb(220, 220, 220);
margin-left: 101px;
}
.rate-radio {
display: inline-block;
}
Now I have this
But I need something like this
Try this:
.rates {
margin-top: 19px;
}
.product-wrapper{
display: inline-block;
background-color: #FFFFFF;
width: 152px;
margin-left: 50px;
}
.rates-block {
width: 100%;
height: 154px;
border: 1px solid rgb(220, 220, 220);
}
.rate-radio {
display: inline-block;
}
<div class="rates">
<div class="product-wrapper">
<div class="rates-block">
<img src="http://www.creativeprintpack.com/images/shoppingbag4.jpg" class="products-img rate-img" alt="product-1" style="width:100%">
</div>
<input class="rate-radio" type="radio" name="radio1" value="wewe">Rate 0</input>
</div>
<div class="product-wrapper">
<div class="rates-block">
<img src="http://www.creativeprintpack.com/images/shoppingbag4.jpg" class="products-img rate-img" alt="product-1" style="width:100%">
</div>
<input class="rate-radio" type="radio" name="radio1" value="wewe">Rate 1</input>
</div>
</div>
I have added a wrapper for each product/rate, which has the width set, the div containing the image is 100% width as the input aswell
When i hover mouse at that time i got the effect but i want to set one image as a by default select when page is load.
Anyone Help me.
Here is my css.
.simpleLens-thumbnails-container a{
display: inline-block;
}
.simpleLens-thumbnails-container a img{
display: block;
}
.all-thumb{
width:50px !important;
}
#demo .img{
border: 5px solid #000;
}
.all-thumb:hover{
box-shadow: 0px 0px 10px #BFCBD5;
}
Here is my PHP code.
<a href="#" id="demo" class="simpleLens-thumbnail-wrapper" data-lens-image="<?php echo $img; ?>" data-bigimage="<?php echo $img; ?>">
<img class="all-thumb" id="demo" src="<?php echo $img; ?>">
</a>
add a class selected to the desired img element like this
$first_item = true;
foreach (............)
{
if($first_item){
<img class="all-thumb selected" id="demo" src="<?php echo $img; ?>">
$first_item = false;
}
else
<img class="all-thumb" id="demo" src="<?php echo $img; ?>">
}
and use this css
.all-thumb.selected, .all-thumb:hover{
box-shadow: 0px 0px 10px #BFCBD5;
}
this will work :)
Add selected to your defult image's class. Desired output for the default image:
<img class="all-thumb selected" id="demo" src="<?php echo $img; ?>">
If you can't hardcode it or do it from the PHP side, use this JQuery code to add the class selected to the first image:
$('.all-thumb:first').addClass('selected');
Then add this JQuery code to your page:
<script>
$(".all-thumb").not(".selected").hover(function(){
$(".all-thumb selected").css("box-shadow","none");
},function(){
$(".all-thumb selected").css("box-shadow","0px 0px 10px #BFCBD5");
});
</script>
It should work. JQuery must be included.
Try this:
Need to add any minimum jquery.
<script src="js/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', '0px 0px 10px #BFCBD5');
$('.simpleLens-thumbnail-wrapper .all-thumb').mouseover(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', 'none');
});
$('.simpleLens-thumbnail-wrapper .all-thumb:first').mouseover(function(){
$('.simpleLens-thumbnail-wrapper .all-thumb:first').css('box-shadow', '0px 0px 10px #BFCBD5');
});
});
</script>
you can also use .hover instead of .mouseover
my fiddle
$szPostContent = $post->post_content;
$szSearchPattern = '#(<img.*?>)#';
$a='';
$aPics='';
preg_match_all( $szSearchPattern, $szPostContent, $aPics );
$iNumberOfPics = count($aPics);
echo "<br />Number of pics on each post...............".$iNumberOfPics;
array_push($postimg, $iNumberOfPics);
$iNumberofPics shows image from single post...
look at the demo ..u will find that on mouseover of arrow imgthe slider dissapears.while i want to show that main div continously until the users remains there on that page..
<div class='container' style='height:150px; width:225px;'>
<div class="imageslider" id="imageslider" style="border: 1px solid #000000; height:150px; width:225px;display:none">
<img class="arrow left" style="border: 1px solid #000000; height:25px; width:25px; float:left; margin-top:50px;" />
<div class="images"></div>
<img class="arrow right" style="border: 1px solid #000000; height:25px; width:25px; float:right; margin-top:50px;" />
</div>
And Script
$(".container").hover(function () {
$(this).find('.imageslider').show();
}, function () {
$(this).find('.imageslider').hide();
});
FIDDLE
.container is there as a placeholder in order for you to be able to mouse it over and out
I am not sure if I got your question right, so I hope one of these approaches help you:
In your code you use onmouseout, not onmouseover. You can:
Use $(...).show() and $(...).hide() on mouseover and mouseout.
Take a look at $(...).toggle() that will take away some work.
I have inserted jquery slide show in to my newly created real estate web site.
My real estate web site runs on 'Openrealty' platform which is php.
Here is a part of my Original jquery code.
if(!repeat)
$this.parent()
.find('li:nth-child('+current+') a')
.stop(true,true)
.animate({'marginRight':'-20px'},300,function(){
$(this).animate({'opacity':'0.7'},700);
});
When I look at where the error comes from through 'Firebug', it shows as follows.
if(!repeat)
$this.parent()
.find('li:nth-child('+current+') a')
.stop(true,true)
.animate(,300,function(){
$(this).animate(,700);
});
Here you can clearly see that some parts of the original code does not renders by the browser. Such as {'marginRight':'-20px'}
As shown by firebug the error begins from " .animate(,300,function(){ " onwards.
I need to find a solution why this Jquery not works in my web site.
Source of this Jquery slide show : http://tympanus.net/codrops/2010/04/28/pretty-simple-content-slider-with-jquery-and-css3/
Any feedback is highly welcomed...
Thanks for the first 2 answers and request.
Yes I removed all (') marks within all styling as per the answers.
But still the error occurs as same above...
Total Jquery script have three parts.
1. Link to http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
2. Link to outside JS file called 'jquery.easing.1.3.js'
3. Inline script
Following is the inline jquery:
<script type="text/javascript">
$(function() {
var current = 1;
var iterate = function(){
var i = parseInt(current+1);
var lis = $('#rotmenu').children('li').size();
if(i>lis) i = 1;
display($('#rotmenu li:nth-child('+i+')'));
}
display($('#rotmenu li:first'));
var slidetime = setInterval(iterate,3000);
$('#rotmenu li').bind('click',function(e){
clearTimeout(slidetime);
display($(this));
e.preventDefault();
});
function display(elem){
var $this = elem;
var repeat = false;
if(current == parseInt($this.index() + 1))
repeat = true;
/* slide in the current one */
if(!repeat)
$this.parent()
.find('li:nth-child('+current+') a')
.stop(true,true)
.animate({marginRight:-20px},300,function(){
$(this).animate({opacity:0.7},700);
});
current = parseInt($this.index() + 1);
var elem = $('a',$this);
elem.stop(true,true).animate({marginRight:0px,opacity:1.0},300);
var info_elem = elem.next();
$('#rot1 .heading').animate({left:-420px}, 500,'easeOutCirc',function(){
$('h1',$(this)).html(info_elem.find('.info_heading').html());
$(this).animate({left:0px},400,'easeInOutQuad');
});
$('#rot1 .description').animate({bottom:-270px},500,'easeOutCirc',function(){
$('p',$(this)).html(info_elem.find('.info_description').html());
$(this).animate({bottom:0px},400,'easeInOutQuad');
})
$('#rot1').prepend(
$('<img/>',{
style : 'opacity:0',
className : 'bg'
}).load(
function(){
$(this).animate({opacity:1},600);
$('#rot1 img:first').next().animate({opacity:0},700,function(){
$(this).remove();
});
}
).attr('src','slide-images/'+info_elem.find('.info_image').html()).attr('width','950').attr('height','300')
);
}
});
</script>
And following is the html part which shows the slide show.
<div id="sliderbox">
<div class="rotator">
<ul id="rotmenu">
<li>
Luxury Life
<div style="display:none;">
<div class="info_image">1.jpg</div>
<div class="info_heading">Best Homes for you</div>
<div class="info_description">
This is description...
Read more
</div>
</div>
</li>
<li>
Smiling Faces
<div style="display:none;">
<div class="info_image">2.jpg</div>
<div class="info_heading">Do at our best</div>
<div class="info_description">
This is description...
Read more
</div>
</div>
</li>
<li>
Tradition
<div style="display:none;">
<div class="info_image">3.jpg</div>
<div class="info_heading">We goes with tradition</div>
<div class="info_description">
This is description...
Read more
</div>
</div>
</li>
<li>
Lands for sale
<div style="display:none;">
<div class="info_image">4.jpg</div>
<div class="info_heading">A best place to live in Kandy</div>
<div class="info_description">
This is description...
Read more
</div>
</div>
</li>
<li>
True Nature
<div style="display:none;">
<div class="info_image">5.jpg</div>
<div class="info_heading">Brings you beauty in nature</div>
<div class="info_description">
This is description...
Read more
</div>
</div>
</li>
</ul>
<div id="rot1">
<img src="" width="950" height="300" class="bg" alt=""/>
<div class="heading">
<h1></h1>
</div>
<div class="description">
<p></p>
</div>
</div>
</div>
</div>
and following is the CSS:
.rotator{
background-color:#222;
width:950px;
height:300px;
margin:0px auto;
position:relative;
/*font-family:'Myriad Pro',Arial,Helvetica,sans-serif;*/
font-family:Helvetica,sans-serif;
color:#fff;
text-transform:uppercase;
/* letter-spacing:-1px; */
letter-spacing:1px;
border:3px solid #f0f0f0;
overflow:hidden;
-moz-box-shadow:0px 0px 10px #222;
-webkit-box-shadow:0px 0px 10px #222;
box-shadow:0px 0px 10px #222;
}
img.bg{
position:absolute;
top:0px;
left:0px;
}
.rotator ul{
list-style:none;
position:absolute;
right:0px;
top:0px;
margin-top:6px;
z-index:999999;
}
.rotator ul li{
display:block;
float:left;
clear:both;
width:260px;
}
.rotator ul li a{
width:230px;
float:right;
clear:both;
padding-left:10px;
text-decoration:none;
display:block;
height:30px;
line-height:30px;
background-color:#222;
margin:1px -20px 1px 0px;
/*opacity:0.7;*/
color:#f0f0f0;
font-size:12px;
border:1px solid #000;
border-right:none;
outline:none;
/*
text-shadow:-1px 1px 1px #000;
*/
-moz-border-radius:10px 0px 0px 5px;
-webkit-border-top-left-radius:10px;
-webkit-border-bottom-left-radius:10px;
border-top-left-radius:10px;
border-bottom-left-radius:10px;
}
/* .rotator ul li a:hover{
text-shadow:0px 0px 2px #fff;
}
*/
.rotator .heading{
position:absolute;
top:0px;
left:0px;
width:500px;
}
.rotator .heading h1{
text-shadow:-1px 1px 1px #555;
font-weight:normal;
font-size:36px;
padding:20px;
}
.rotator .description{
width:300px;
height:15px;
position:absolute;
bottom:0px;
left:0px;
padding:5px;
background-color:#222;
-moz-border-radius:0px 10px 0px 0px;
-webkit-border-top-right-radius:10px;
border-top-right-radius:10px;
/*opacity:0.7;*/
border-top:1px solid #000;
border-right:1px solid #000;
}
.rotator .description p{
/*text-shadow:-1px 1px 1px #000;*/
text-transform:none;
letter-spacing:normal;
line-height:10px;
font-family:Helvetica,sans-serif;
font-size:13px;
}
a.more{
color:orange;
text-decoration:none;
text-transform:uppercase;
font-size:10px;
}
a.more:hover{
color:#fff;
}
I have analysed every of these scripts but couldn't identified any issues...
Please tell me how I can solve this.
Try this in you original code.
if(!repeat)
$this.parent()
.find('li:nth-child('+current+') a')
.stop(true,true)
.animate({marginRight:-20},300,function(){
$(this).animate({opacity:0.7},700);
});
Your CSS properties for the animate() function seem wrong.
Experiment without the ' (single quote characters)
if(!repeat)
$this.parent()
.find('li:nth-child('+current+') a')
.stop(true,true)
.animate({marginRight:'-20px'},300,function(){
$(this).animate({opacity:0.7},700);
});
As in the animate() examples from the jquery webpage