Position of image in the centre of window by javascript - php

I'm trying to made made zoom preview image. It's almost work but I need to show it in the centre of my window by Y and move left right with cursor. Now my large image move in X and Y. How to fixed it? I understand that I have to change e.pageY but for what?
this.product_img_link = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
/* END CONFIG */
$("a.product_img_link").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='product_img_link'><img src='"+ this.rel +"' ' alt='Image preview' /> "+ c +"</p>");
$("#product_img_link")
.css("top",(e.pageY -100) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#product_img_link").remove();
});
$("a.product_img_link").mousemove(function(e){
$("#product_img_link")
.css("left",(e.pageX + yOffset) + "px");
});
};
$(document).ready(function(){
product_img_link();
});
And this is my template:
<script type="text/javascript" src="/modules/productimage/js/zoomi.js"></script>
<link media="all" type="text/css" rel="stylesheet" href="/modules/productimage/css/product_zoom.css">
{if isset($products)}
<!-- Products list -->
<ul id="product_list" class="clear">
{foreach from=$products item=product name=products}
<li class="ajax_block_product {if $smarty.foreach.products.first}first_item{elseif $smarty.foreach.products.last}last_item{/if} {if $smarty.foreach.products.index % 2}alternate_item{else}item{/if} clearfix">
<div class="left_block">
{if isset($comparator_max_item) && $comparator_max_item}
<p class="compare">
<input type="checkbox" class="comparator" id="comparator_item_{$product.id_product}" value="comparator_item_{$product.id_product}" {if isset($compareProducts) && in_array($product.id_product, $compareProducts)}checked="checked"{/if} />
<label for="comparator_item_{$product.id_product}">{l s='Select to compare'}</label>
</p>
{/if}
</div>
<div class="center_block">
<a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" rel="{$link->getImageLink($product.link_rewrite, $product.id_image, 'large_default')}">
<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" alt="gallery thumbnail" /></a>

If you want to find the center "y" point for the window, using jQuery:
$(window).height() / 2
This will find the height of the window and divide by two to find the center.
You could replace "e.pageY" with this, however the image will still appear a bit off-center.
To fully center it, you will also want to adjust the image's "y" position up a bit so that the center point of the image is at the center point of the window. So, we can do something similar to the paragraph holding the image to find its center point, leading us to code that looks like this:
($(window).height() / 2) - ($('#product_img_link').height() / 2)
...making your full jQuery css statement look like this:
$("#product_img_link")
.css("top",( ($(window).height() / 2) - ($('#product_img_link').height() / 2) ) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");

Related

A option of night mode in an app which automatically reduces the screen brightness. Will it workout using some php or html or css code?

This code is basic one which changes the background to black one.
PHP CODE
if ($res160[0] == "1") {
echo "<script>$('body').css('background-color', 'black'); $('body').css('color', 'white');</script>";
}
How do I write a code to reduce the brightness?
There is a CSS property filter which is used to reduce the brightness.
filter: brightness(50%);
Hope this is what you are looking for.
I would do this by changing the brightness of the container(body or div) something like this.
var x = $("#myRange");
$("body").css({
"opacity": x.val()
});
x.on("change mousemove", function() {
$("#contents").css({
"filter": "brightness(" + $(this).val() * 100 + "%)"
});
});
div {
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
Choose Light Level<br>
<input id='myRange' type="range" min="0.3" max="1" step="0.1" value=1><br> dark -> light
<div id="contents">
<div style="">
<img src="http://lorempixel.com/100/100/nightlife/Dummy-Text">
<img src="http://lorempixel.com/100/100/food/Dummy-Text">
</div>
<div style="background-color: red;">
<img src="http://lorempixel.com/100/100/nightlife/Dummy-Text">
<img src="http://lorempixel.com/100/100/food/Dummy-Text">
</div>
</div>

select box in model window as list items

I want to make a select box like pop up item, I come accross with this link
http://tympanus.net/Tutorials/NaturalLanguageForm/
In that they have done select box overwrite method. when clicking on the food it opens in popup about list of the items.
can anyone please tell me how to do similar to this with jquery..
how about this
jsfiddle
<div data-role="header" data-theme="b"><h1>click for option</h1></div>
<p >
<ul>
<li> item 1 </li>
<li> item 2 </li>
<li> item 3 </li>
</ul>
</p>
You can do something like this. Check the Fiddle
<div class="ui-bar ui-bar-c"> open the dialog
Script
$('#page1').bind('pageinit', function () {
picache = "http://jquerymobile.com/test/docs/_assets/images/jquery-logo.png";
$('#pop1,#pop2').bind('popupbeforeposition popupafteropen popupafterclose', function (e) {
var thm = e.type == 'popupbeforeposition' ? 'b' : (e.type == 'popupafteropen' ? 'd' : 'e'),
tgt = $(e.target).attr('id');
style = tgt == 'pop2' ? 'style="color: firebrick; font-size:1.2em;"' : "";
$('#log').append('<li data-theme="' + thm + '"' + style + '>' + tgt + ": " + e.type + ' raised</li>').listview('refresh');
});
$('#log').on('taphold dblclick', function () {
$(this).find('li').remove();
});
});

How to apply jquery for particular class

I am showing images in list with having next and previous button.
I have use this jquery in for loop so that it can more than one.
list1:
Prev <ul><li> img1 img2 img3....</li></ul> Next
list2:
Prev <ul><li> img1 img2 img3....</li></ul> Next
if i have three different image list on same page if i click on next Or prev of 1st list then its apply for all list.
how can i apply it for that particular list to move Next and prev.
I have used the code from ths link:http://css-plus.com/2010/09/create-your-own-jquery-image-slider/
i have used folloeing code:
Jquery:
$(document).ready(function(){
// Gallery
if(jQuery(".gallery").length){
// Declare variables
var totalImages = jQuery(".gallery > li").length,
imageWidth = jQuery(".gallery > li:first").outerWidth(true),
totalWidth = imageWidth * totalImages,
visibleImages = Math.round(jQuery(".gallery-wrap").width() / imageWidth),
visibleWidth = visibleImages * imageWidth,
stopPosition = (visibleWidth - totalWidth);
jQuery(".gallery").width(totalWidth);
jQuery("#gallery-prev").click(function(){
if(jQuery(".gallery").position().left < 0 && !jQuery(".gallery").is(":animated")){
jQuery(".gallery").animate({left : "+=" + imageWidth + "px"});
}
return false;
});
jQuery("#gallery-next").click(function(){
if(jQuery(".gallery").position().left > stopPosition && !jQuery(".gallery").is(":animated")){
jQuery(".gallery").animate({left : "-=" + imageWidth + "px"});
}
return false;
});
}
});
Html and php:
<?php foreach($records as $row) :?>
<div id="gallery-wrap">
<ul id="gallery" class="gallery">
<?php foreach($row['images'] as $image) :?>
<li>
<img src="<?php echo base_url();?>uploads/<?php echo $image['img']; ?> />
</li>
<?php endforeach ;?>
</ul>
</div>
<div id="gallery-controls" class="gallery-controls">
<a href="#" id="gallery-prev" >Prev</a>
<a href="#" id="gallery-next" >Next</a>
</div>
<?php endforeach ;?>
ok first of all....
1) IDs should always be unique... but in your case you have elements with same ID since it is in loop.. so either change it and makeit unique OR you can change it to class in your HTML code...
<div class="gallery-wrap">
-----^^---- change to class...
2) since you are using class , all your ID selector i.e # should be replaced by class selector . in your jquery code.
jQuery(".gallery-prev").click(function(){
--------^------ here
changes in your
HTML
<div class="galleryDisplayBlock"> //add new div
<div class="gallery-wrap">
<ul class="gallery">
<?php foreach($row['images'] as $image) :?>
<li>
<img src="<?php echo base_url();?>uploads/<?php echo $image['img']; ?> />
</li>
<?php endforeach ;?>
</ul>
</div>
<div class="gallery-controls">
<a href="#" class="gallery-prev" >Prev</a>
<a href="#" class="gallery-next" >Next</a>
</div>
</div>
JQuery
jQuery(".gallery-prev").click(function(){
var thisGallery=jQuery(this).parent();
if(thisGallery.find(".gallery").position().left < 0 && !thisGallery.find(".gallery").is(":animated")){
thisGallery.find(".gallery").animate({left : "+=" + imageWidth + "px"});
}
return false;
});
jQuery(".gallery-next").click(function(){
var thisGallery=jQuery(this).parent();
if(thisGallery.find(".gallery").position().left > stopPosition && !thisGallery.find(".gallery").is(":animated")){
thisGallery.find(".gallery").animate({left : "-=" + imageWidth + "px"});
}
return false;
});

Choose where to insert my youtube video

I have this code which I found on Stack a few weeks ago.
<script type="text/javascript">
$(document).ready(function() {
// I added the video size here in case you wanted to modify it more easily
var vidWidth = 300; // 425;
var vidHeight = 200; // 344;
var obj = '<object width="' + vidWidth + '" height="' + vidHeight + '">' + '<param name="movie" value="http://www.youtube.com/v/[vid]&hl=en&fs=1">' + '</param><param name="allowFullScreen" value="true"></param><param ' + 'name="allowscriptaccess" value="always"></param><em' + 'bed src="http://www.youtube.com/v/[vid]&hl=en&fs=1" ' + 'type="application/x-shockwave-flash" allowscriptaccess="always" ' + 'allowfullscreen="true" width="' + vidWidth + '" ' + 'height="' + vidHeight + '"></embed></object> ';
$('.posthold:contains("youtube.com/watch")').each(function() {
var that = $(this);
var vid = that.html().match(/v=([\w\-]+)/g); // end up with v=oHg5SJYRHA0
that.html(function(i, h) {
return h.replace(/(http:\/\/www.youtube.com\/watch\?v=+\S+\S?)/g, '');
});
if (vid.length) {
$.each(vid, function(i) {
that.append(obj.replace(/\[vid\]/g, this.replace('v=', '')));
});
}
});
});
</script>
It works great at embeding videos from url's. But I have a small problem with it that I have been trying to solve but i keep breaking the code.
Basically I have the following div setup
<div class="grid_10 alpha omega posthold" >
<div class="clearfix">
<div class="grid_2 alpha">
<img src="/images/no-image/logo_default.jpg" width="100" height="100" />
</a></div>
<div class="grid_8 omega">
<h1>Some Name Here</h1>
<p>Some Comment here</p>
</div>
</div>
</div>
Im trying to get the video to appear directly after the closing paragraph tag where it says some comment here. The user enters the video as part of a post. I store the post in a database and when I pull the post out I swap the url from youtube to the embed code. This is a repeating div so there maybe many instances that a video appears. Is this even possible. At the minute the video appears after the last closing div tag.

How do I add links to images in this javascript?

I need help please. How do I add links to images in the code below. This is a script that allows visitors to click a choice on a dropdown menu in a form, and every choice changes the image presented. I am trying to add a link to each image that will allow the visitors to hover their mouse over the image and it opens up a larger image.
I just need to know where to add the link. Everytime I add it in the var sel_imgs=[ , it disables the function of changing the images when the visitor selects an option in the dropdown menu.
function diva_imgBySel(objId,theValue) { //v0.1 divaHTML.com
var sel_imgs=["images/md01.jpeg","images/md01.jpeg","images/md02.jpeg","images/md03.jpeg","images/md04.jpeg","images/md06.jpeg","images/md05.jpeg","images/pic07.jpeg","images/pic08.jpeg"];
var d=document;
theValue=sel_imgs[theValue];
if (!theValue || !d.getElementById ) return;
var obj = d.getElementById(objId);
if (obj) obj.src=theValue;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>
And here is the form code lower down on the page:
<img src="images/md01.jpeg" alt="" name="theImg" width="147" height="161" id="theImg" style="border: 1px solid #ffffff;" align="LEFT" /><strong>Add a vase:</strong>
<input type="checkbox" name="anniv" id="anniv" value="6.95" onclick="priceUpdate('anniv');"/>
£6.95
</td>
<td width="71%" align="left" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"></br> <select name="productColors" id="productColors" style="width:270px; margin-bottom:5px; margin-top:5px" onchange="diva_imgBySel('theImg',this.selectedIndex)">
<option value="MD1004">Select Flower Arrangement</option>
<option value="MD1004">Bloom</option>
<option value="MD1001">Majestic</option>
<option value="MD1007">Mothers Day Premium</option>
<option value="MD1002">Mum's the Word</option>
<option value="NF1011">Joyful Orchids</option>
<option value="NF1010">Lily and Rose Hand Tied</option>
<option value="NF1013">Sunflower Sensation</option>
<option value="SF002-free-vase">Tranquililty</option>
</select></td>
Here is the node with the mouseover effect attached. it works fine, but repeats the same large image for each selection the user makes. I need to know how to duplicate this effect for each image not just "md01.jpeg".
<a href="#" rel="imgtip[1]"><img src="images/md01.jpeg" alt="" name="theImg" width="147" height="161" id="theImg" style="border: 1px solid #ffffff;" align="LEFT" /><a/>
<link rel="stylesheet" type="text/css" href="ddimgtooltip.css" />
<script type="text/javascript" src="ddimgtooltip.js">
/***********************************************
* Image w/ description tooltip v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/
</script>
Here is the code for image mouseover. It is a .js file
/* Image w/ description tooltip v2.0
* Created: April 23rd, 2010. This notice must stay intact for usage
* Author: Dynamic Drive at http://www.dynamicdrive.com/
* Visit http://www.dynamicdrive.com/ for full source code
*/
var ddimgtooltip={
tiparray:function(){
var tooltips=[]
//define each tooltip below: tooltip[inc]=['path_to_image', 'optional desc', optional_CSS_object]
//For desc parameter, backslash any special characters inside your text such as apotrophes ('). Example: "I\'m the king of the world"
//For CSS object, follow the syntax: {property1:"cssvalue1", property2:"cssvalue2", etc}
tooltips[0]=["images/pic01.jpg"]
tooltips[1]=["images/pic02.jpg"]
tooltips[2]=["images/pic03.jpg"]
tooltips[3]=["images/pic04.jpeg"]
tooltips[4]=["images/pic05.jpeg"]
tooltips[5]=["images/pic06.jpeg"]
return tooltips //do not remove/change this line
}(),
tooltipoffsets: [20, -30], //additional x and y offset from mouse cursor for tooltips
//***** NO NEED TO EDIT BEYOND HERE
tipprefix: 'imgtip', //tooltip ID prefixes
createtip:function($, tipid, tipinfo){
if ($('#'+tipid).length==0){ //if this tooltip doesn't exist yet
return $('<div id="' + tipid + '" class="ddimgtooltip" />').html(
'<div style="text-align:center"><img src="' + tipinfo[0] + '" /></div>'
+ ((tipinfo[1])? '<div style="text-align:left; margin-top:5px">'+tipinfo[1]+'</div>' : '')
)
.css(tipinfo[2] || {})
.appendTo(document.body)
}
return null
},
positiontooltip:function($, $tooltip, e){
var x=e.pageX+this.tooltipoffsets[0], y=e.pageY+this.tooltipoffsets[1]
var tipw=$tooltip.outerWidth(), tiph=$tooltip.outerHeight(),
x=(x+tipw>$(document).scrollLeft()+$(window).width())? x-tipw-(ddimgtooltip.tooltipoffsets[0]*2) : x
y=(y+tiph>$(document).scrollTop()+$(window).height())? $(document).scrollTop()+$(window).height()-tiph-10 : y
$tooltip.css({left:x, top:y})
},
showbox:function($, $tooltip, e){
$tooltip.show()
this.positiontooltip($, $tooltip, e)
},
hidebox:function($, $tooltip){
$tooltip.hide()
},
init:function(targetselector){
jQuery(document).ready(function($){
var tiparray=ddimgtooltip.tiparray
var $targets=$(targetselector)
if ($targets.length==0)
return
var tipids=[]
$targets.each(function(){
var $target=$(this)
$target.attr('rel').match(/\[(\d+)\]/) //match d of attribute rel="imgtip[d]"
var tipsuffix=parseInt(RegExp.$1) //get d as integer
var tipid=this._tipid=ddimgtooltip.tipprefix+tipsuffix //construct this tip's ID value and remember it
var $tooltip=ddimgtooltip.createtip($, tipid, tiparray[tipsuffix])
$target.mouseenter(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.showbox($, $tooltip, e)
})
$target.mouseleave(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.hidebox($, $tooltip)
})
$target.mousemove(function(e){
var $tooltip=$("#"+this._tipid)
ddimgtooltip.positiontooltip($, $tooltip, e)
})
if ($tooltip){ //add mouseenter to this tooltip (only if event hasn't already been added)
$tooltip.mouseenter(function(){
ddimgtooltip.hidebox($, $(this))
})
}
})
}) //end dom ready
}
}
//ddimgtooltip.init("targetElementSelector")
ddimgtooltip.init("*[rel^=imgtip]")
This code sample doesn't actually refer to the markup you want to focus on. WHat you've got here is the logic and form elements will change the src of the img tag with an id of 'theImg'. What you need to look at is the element with the 'theImg' id and add a listener there to fire whatever large image effect that you want.
<option value="MD1001"><img src="your_image_path"/>Your non-Link Text</option>
That's how I would lay it out. I'm not sure what exactly your asking for. But this will put an image in there. Just replace the "your_link" , "your_image_path" with your data.

Categories