The idea is to create a square thumbnail defined by whether the height or width is greater. It simply is not doing anything. Can someone please point me in the right direction?
Thanks
Dan
function galDisplay(){
var galSingleImgH(this).height();
var galSingleImgW(this).width();
var galSingleImgWSum(this).width()/2;
var galSingleImgHSum(this).height()/2;
if(galSingleImgW > galSingleImgH){
jQuery(this).attr('style','height:63px;width:auto;margin-left:50%;left:-'+ galSingleImgWSum +'px;');
} else {
jQuery(this).attr('style','height:auto;width:63px;margin-top:50%;top:-'+ galSingleImgHSum +'px;');
}
}
jQuery('.rhsGallery .notFirst a img').galDisplay();
-
Yes- there are 3 images that it should affect and it's within the (document).ready()ggdx– ggdx2013年02月26日 10:09:20 +00:00Commented Feb 26, 2013 at 10:09
4 Answers 4
Your variable definitions are wrong, use this instead:
var galSingleImgH = jQuery(this).height();
var galSingleImgW = jQuery(this).width();
var galSingleImgWSum = jQuery(this).width()/2;
var galSingleImgHSum = jQuery(this).height()/2;
1 Comment
galDisplay is a global, not a method of jQuery objects. See the jQuery documentation of plugin authoring.
It looks like changing
function galDisplay(){
to
jQuery.fn.galDisplay = function (){
should do the job.
You will also need to fix your syntax errors.
var galSingleImgH(this).height();
should be
var galSingleImgH = this.height();
... and so on.
Comments
I think you forgot some =s on the upper 4 lines:
(oh, and wrong way of calling galDisplay())
function galDisplay(){
var galSingleImgH = (this).height();
var galSingleImgW = (this).width();
var galSingleImgWSum = (this).width()/2;
var galSingleImgHSum = (this).height()/2;
if(galSingleImgW > galSingleImgH){
jQuery(this).attr('style','height:63px;width:auto;margin-left:50%;left:-'+ galSingleImgWSum +'px;');
} else {
jQuery(this).attr('style','height:auto;width:63px;margin-top:50%;top:-'+ galSingleImgHSum +'px;');
}
}
galDisplay(jQuery('.rhsGallery .notFirst a img'));
Comments
To start with, your code is wrong:
var galSingleImgH(this).height();
var galSingleImgW(this).width();
var galSingleImgWSum(this).width()/2;
var galSingleImgHSum(this).height()/2;
This won't ever work. I'd advise you to use Developer Tools to see this error in your browser.
It should be:
var galSingleImgH = (this).height();
var galSingleImgW = (this).width();
var galSingleImgWSu = (this).width()/2;
var galSingleImgHSum = (this).height()/2;
Secondly, if this doesn't correct things, can you include your rhsGallery HTML in your question?