I'm changing the opacity of a class by using the jQuery hover function.
Note : I'm not using the
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
Here is my code:
<script type="text/javascript">
$(document).ready(function(){
$(".thumbnail_image_related_project .transparent_font").css({'opacity' : '0'});
$(".thumbnail_image_related_project").hover(
function(){
$(this).children(".transparent_font").stop().animate({'opacity' : '0.7'}, 300);
},
function(){
$(this).children(".transparent_font").stop().animate({'opacity' : '0'}, 300);
}
);
});
</script>
This code is working perfectly on a laptop but not on a smartphone.
The problem: When I clicked on the element, the animation is working and I'm going to next page. But, when I going back to the previous page, the opacity of the element isn't initialised.
Does some one know why?
Here is my php code:
<a href="http://192.168.0.11/next-page/" title="blabla">
<div class="thumbnail_image_related_project">
<h2 class="transparent_font">Text and the white background</h2>
<div id="image">
<img width="300" height="173" src="http://192.168.0.11/blabla.jpg"/>
</div>
</div>
</a>
here is my css:
.thumbnail_image_related_project .transparent_font{
line-height: 1.25em;
position: absolute;
top: 0;
left: 0;
color: black;
background-color:white;
width: 100%;
height: 100%;
opacity:0;
}
Are you using jQuery or jQuery Mobile? The reason I ask is that on mobile, it is likely a touchstart event not hover. jQuery Mobile may convert touchstart into hover.
Take a look at this: jQuery hover event on tag on mobile devices.
Related
i am trying to add class (.trans) to my newly made clone in jquery. .but its not working.
...
when i am applying class directly to my object then its working perfectly.
What i am trying to do is..
i fetch some images from database to my page.
with foreach loop i displayed those images..
then with the help of jquery clone method i create a clone of particular image when i clicked on it and the clone will displayed
in a different div.
now i want to add a particular class to my newly created clone. but its not working..
(NOTE: when i am applying the same class directly on the fresh object(not clone) that time its working)
only for reference final result should look like this but after making clone.. http://jsfiddle.net/66Bna/293/
here is my code...
<?php
$image = "1.jpg,2.jpg,3.jpg,4.jpg,5.jpg";
$image = explode(",", $image);
?>
<html>
<head>
<link rel="stylesheet" href="../css/jquery.freetrans.css">
<link rel="stylesheet" href="../css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".my_image").click(function(){
$(this).clone().addClass("trans").appendTo(".block");
});
});
</script>
<style>
body{
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
-ms-user-select: none;
}
.shape{
width: 300px;
height: 250px;
background-color: #B2D237;
color: #123456;
}
#bounds {
position: absolute;
border: 1px solid red;
}
.block{
width:100%;
background:red;
}
</style>
</head>
<body>
<div class="library">
<ul>
<?php
foreach ($image as $key => $img) {
echo "<li class='img_block'><img class='my_image' src='assets/$img'></li>";
}
?>
</ul>
</div>
<div class="block"></div>
<script src="../js/Matrix.js"></script>
<script src="../js/jquery.freetrans.js"></script>
<script>
$(function(){
// do a selector group
$('.trans').freetrans({
x: 50,
y: 50
});
//updating options, chainable
$('#two').freetrans({
x: 200,
y: 100,
angle: 45,
'rot-origin': "50% 100%"
})
.css({border: "1px solid pink"})
var b = $('#two').freetrans('getBounds');
console.log(b, b.xmin, b.ymax, b.center.x);
$('#bounds').css({
top: b.ymin,
left: b.xmin,
width: b.width,
height: b.height
})
})
</script>
</body>
</html>
Ok, look. What is happening is that you're activating the Free Transform plugin in the end of the document and all the plugin does is to take the existing elements with that class and give them the features.
When we add elements and classes dynamically, they're not being taken in account by the plugin because by the time the plugin was being called, the elements didn't exist.
Understood?
So, seeing that I don't have the proper development environment for this, I will suggest some possible solutions:
1) Put this script at the bottom, below the Free Transform plugin declaration
<script>
$(document).ready(function(){
$(".my_image").click(function(){
$(this).clone().addClass("trans").appendTo(".block");
});
});
</script>
2) Initialize the plugin for each added element EDIT: Fixed some logic mistake
<script>
$(document).ready(function(){
$(".my_image").click(function() {
$(this).clone().appendTo(".block").freetrans({
x: 50,
y: 50
});;
});
});
</script>
Just try that for now
after appending some data in an iframe using JQuery i need to reload the appended data. the data contains some script tags.
this is an example of the code i appended to an iframe. the div will apear into the iframe but the script won't work. the alert i added appears but for some reason the JQuery code won't transform the div into a dialog.
I said maybe it's because i should reload the appended data in this iframe. is it possible?
<style>
.draggable { width: 90px; height: 80px; padding: 5px; float: left; margin: 0 10px 10px 0; font-size: .9em; }
.ui-widget-header p, .ui-widget-content p { margin: 0; }
#snaptarget { height: 140px; }
</style>
<script type="text/javascript">
$(function() {
window.alert("TEST dialog1");
$( "#dialog1" ).dialog({ title: "Notifications Widget" });
$( "#dialog1" ).dialog( "option", "position", [200,200] );
$( "#dialog1" ).dialog().parents(".ui-dialog").draggable("option", "snap", true);
});
</script>
<div id="dialog1" class="draggable ui-widget-content">
<p>I am a notification widget</p>
</div>
thanks for helping
the alert i added appears but for some reason the JQuery code won't
transform the div into a dialog.
Alert appears, so your script is actually added and works fine. Remember that you must have jQuery, jQuery UI, css or what ever else required for your code to work correctly being linked inside iFrame just like . It has no direct access to parent window code. You may think about it like another browser tab/window.
I have a many div with same class pro3 and an image with class showcatdiv
And this are appended on any image on wordpress page ..I want to show div with pro3 on hover of showcatdiv Below is my pro3 div
<div class="pro3catProducts" style=" background-color: #FFFFFF; border: 0px solid black;
height: 279px; left: '200'px; opacity: 0.55; padding-left: 10px;
position: relative; top: '100'px; width: 39px; display:none;">
<IMG class="catsmallImages" id="catsmallImages1" SRC="Images/fashion.png" BORDER="1" ALT="" style="height: 37px; padding: 3px; width: 28px;">
<IMG class="catsmallImages" id="catsmallImages2" SRC="Images/fashion.png" BORDER="1" ALT="">
</div>
I have written a javascript for it
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
// script dependent on jQuery
alert("test");
jQuery(".showcatdiv").hover(function(){
//alert("test324");
jQuery(".pro3catProducts").show();
});
}
</script>
With this it is showing the pro3 div on every image..I want to show on that particular image ??
First image show the image on which i want to have a hover effect ...And the second image does what i need but i just want on that perticular image and here it is showing on all images..
If pro3 and showcatdiv are both in maindiv, and you want to show pro3 when you hover over showcatdiv, you can use CSS to achieve that:
.pro3 {
display: none;
}
.showcatdiv:hover+.pro3 {
display: block;
}
http://jsfiddle.net/KvrGk/2/
No need for JavaScript, especially jQuery. Do however check the support for the sibling selector.
There is no relation between pro3 and showcatdiv...They both r in one div Maindiv
seeing your comment if they are inside one div.. then use this reference get parent and find .pro3catProducts
try this..
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
alert("test");
jQuery(".showcatdiv").hover(function(){
jQuery(this).parent().find(".pro3catProducts").show(); //<--here
});
}
</script>
OK, let's assume the img is a sibling of pro3 div in this way:
<img class="showCatDiv" ... />
<div class="pro3..." ... >...</div>
Then the JS would be:
$('.showCatDiv').hover(function(){
$(this).parent().find('.pro3').show();
});
which finds their common parent and then looks for this pro3 div to be shown.
Or
$('.showCatDiv').hover(function(){
$(this).next('.pro3').show();
});
which relies on the pro3 div to be the sibling of img.
I have absolute positioned "containers" in witch my java elements are running. the background image is working responsive with the page but the "containers" are not scaling. Is there a way to make them scale with the image that they are positioned "on-top" of ? here is some of the code I'm using.
CSS
#forest2 {
width: 960px;
max-width: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
}
PHP
<div class="forest2" style = "position: relative" >
<img src = "http://xxx/wordpress/wp-content/uploads/2013/01/xxx.png">
<div style = "position: absolute; top: 315px; left: 24px;" class="slideshow0" >
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/1.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/2.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/3.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/4.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/5.jpg"/>
</div>
Script statement .. if needed but probably not
<script type="text/javascript">
$(document).ready(function() {
$('.slideshow0').cycle({
fx: 'fade',
random: true,
timeout: 6000,
speed: 3000,
delay: 100,
});
Resolved with a different method. Adapted AS3 to work in place of java. It works with the responsive design and all the variables are passed fine.
Language: PHP and jQuery
What I'm trying to do is pop up a dynamic link when a user clicks on it.
I don't want the page to be opened in a new window though, but in a modal one which overlays on the current page.
So with javascript, when a user clicks on this link, the action is to find the link's attr href and make a code for THAT link to be inside an iframe within the modal window.
The HTML with dynamic PHP link:
<img src="./img/Facebook.png" style="float: right; margin-top: 0px;" title="Share on Facebook" alt="Share on Facebook" id="<?php echo $rows['id']; ?>">
The jQuery script:
var makePop = function() {
link = $(this).attr('href');
return '<div class="the_box" id="box" style="display: block;"><a class="boxclose" id="boxclose"></a>
<iframe src="' + link + '" height="500px" width="600px" id="" name="iframe"></iframe></div>';
} // End of Function.
$("a.fblink").click(makePop);
I don't know how to make this happen... This is not working.
Anybody? :o)
There's no point returning a string from an event handler function, it won't do anything.
You need to actually create the modal window. Try jQuery UI for this.
The following should provide what your looking for. However would need to consider issues such as same origin policy for the XHR 'load' call.
See example at: http://jsfiddle.net/qeXea/2/
Note: Due to same origin policy the iframe isn't able to populate with the content, simply setup your own page on your website and use your own urls to view.
HTML
Click Here
<div id="fade"></div>
<iframe id="dialog" src=""></iframe>
<script type="text/javascript">
function launchUrl(owner) {
$('#fade').show();
var link = $(owner).attr('href');
$('#dialog').load(link, function(response) {
$('#dialog').show();
});
}
</script>
CSS
#fade {
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
display: none;
position: absolute;
background-color: rgba(255, 255, 255, 0.5);
}
#dialog {
top: 100px;
left: 100px;
width: 200px;
height: 200px;
z-index: 101;
display: none;
position: absolute;
}
Alternative
HTML
Click Here
<div id="fade"></div>
<iframe id="dialog" src=""></iframe>
<script type="text/javascript">
function launchUrl(link) {
$('#fade').show();
$('#dialog').load(link, function(response) {
$('#dialog').show();
});
}
</script>