Here is my site (click here) I 'm trying to get the background image to change on hover of a menu item, and I'm getting close! However, when I hover, the menu disappears and the swap back to the original image is not smooth like I'd like. Any ideas on how I can improve this??
<?php
/*
Template Name: Page - All Projects
*/
?>
<?php get_header(); ?>
<?php
/* #Start the Loop
======================================================*/
if (have_posts()) : while (have_posts()) : the_post();
?>
<?php
/* #Get Fullscreen Background
======================================================*/
$pageimage = get_post_meta($post->ID,'_thumbnail_id',false);
$pageimage = wp_get_attachment_image_src($pageimage[0], 'full', false);
ag_fullscreen_bg($pageimage[0]);
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
//rollover swap images with rel
var img_src = "$pageimage";
var new_src = "";
$(".rollover").hover(function(){
//mouseover
img_src = $(this).attr('src'); //grab original image
new_src = $(this).attr('rel'); //grab rollover image
$(this).attr('src', new_src); //swap images
$(this).attr('rel', img_src); //swap images
},
function(){
//mouse out
$(this).attr('src', img_src); //swap images
$(this).attr('rel', new_src); //swap images
});
//preload images
var cache = new Array();
//cycle through all rollover elements and add rollover img src to cache array
$(".rollover").each(function(){
var cacheImage = document.createElement('img');
cacheImage.src = $(this).attr('rel');
cache.push(cacheImage);
});
})(jQuery);
</script>
<div class="contentarea">
<div id='cssmenu'>
<ul>
<li class='has-sub '><a href='#'>Center Consoles</a>
<ul>
<li class='sub'><a href='http://takeitto11.com/striper2015/portfolio/2oo-cc/'><img class="rollover" width="1500px" height="1000px" rel="http://takeitto11.com/striper2015/wp-content/uploads/2014/10/Striper_HPS_1500x150010.jpg" />200 CC</a></li>
<li class='sub'><a class="220CC" href='#'>220 CC</a></li>
<li class='sub'><a class="2605CC" href='#'>2605 CC</a></li>
</ul>
</li>
<li class='has-sub '><a href='#'>Dual Consoles</a>
<ul>
<li class='sub'><a class="200DC" href='#'>200 DC</a></li>
<li class='sub'><a class="220DC" href='#'>220 DC</a></li>
</ul>
</li>
<li class='has-sub '><a href='#'>Walk Arounds</a>
<ul>
<li class='sub'><a class="200WA" href='#'>200 Walk Around</a></li>
<li class='sub'><a class="220WA" href='#'>220 Walk Around</a></li>
<li class='sub'><a class="2601WA" href='#'>2601 Walk Around</a></li>
<li class='sub'><a class="2901WA" href='#'>2901 Walk Around</a></li>
</ul>
</li>
</div>
<div class="clear"></div>
</ul>
Thank You!!
Related
how to create menu and sub menu html from angular with database MySql.
i have table from mysql like this.
id menu
1 master
2 aplikasi
3 laporan
menu.php
<div id='cssmenu'>
<ul>
<li ><a href='#'><span>HOME</span></a></li>
<li class='has-sub'><a href='#'><span>Master</span></a>
<ul>
<li><a ui-sref="user" ui-sref-active="active"><span>User</span></a></li>
<li><a ui-sref="produk" ui-sref-active="active"><span>Produk</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Aplikasi</span></a>
<ul>
<li><a ui-sref="transaksi" ui-sref-active="active"><span>Transaksi</span></a></li>
<li><a ui-sref="stok" ui-sref-active="active"><span>Stok Barang</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>laporan</span></a>
<ul>
<li><a ui-sref="itt" ui-sref-active="active"><span>Item terdisplay</span></a></li>
</ul>
</li>
</ul>
</div>
<!-- my app.js-->
var app = angular.module("app",['ui.router']); // jangan lupa kita inject module ui.router
app.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state("itt",{
url: "/itt",
templateUrl : "modul/itt/itt.php"
})
.state("home",{
url : "/home",
templateUrl : "home.php" // path template
})
.state("user",{
url: "/user",
template : "<h1>Halaman User</h1>"
//controller : "Menu3Ctrl"
})
.state("produk",{
url: "/produk",
template : "<h1>Halaman Produk</h1>"
//controller : "Menu3Ctrl"
})
.state("transaksi",{
url : "/transaksi",
template : "<h1>Halaman Transaksi</h1>"
});
$urlRouterProvider.otherwise("home");
});
i want replace menu in menu.php with my menu in database
I wrote my site with php. I have the index file dynamically loading my pages from a pages folder. I have the nav menu in a separate file as well.
so I'm trying to have the text color highlighted when clicked, since I can't get the windowlocation to work. Because of the way I have it setup, the windowlocation returns /index.php with javascript or jquery. So I tried to keep it simple by just targeting the link.
<nav>
<ul>
<li>Home</li>
<li>Skills</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!--Script to add selected class to highlight active link-->
<script>
$(document).ready(function(){
$("ul li a").click(function(){
$("ul li a").removeClass('selected');
$("ul li a").addClass('selected');
});
});
</script>
my css is setup like this:
a.selected{color:#0066ff;}
I've tried throwing this code in every php file I created. Still nothing works. When I want an alert box to pop up with a message when a link is clicked, that works fine. why does this not work? Nothing changes when I run the code... Any suggestions?
If you reload the page by clicking each link then try
<nav>
<ul>
<li><a href="index.php?p=home" <?php (empty($_GET['p']) || $_GET['p'] == 'home') ? echo 'class="selected"' : ''?> >Home</a></li>
<li><a href="index.php?p=skills" <?php $_GET['p'] == 'skills' ? echo 'class="selected"' : ''?>>Skills</a></li>
<li><a href="index.php?p=about" <?php $_GET['p'] == 'about' ? echo 'class="selected"' : ''?>>About</a></li>
<li><a href="index.php?p=contact" <?php $_GET['p'] == 'contact' ? echo 'class="selected"' : ''?> >Contact</a></li>
</ul>
</nav>
Though you won't need the jQuery function.
If you don't want to reload the page then try this in your jQuery:
$(document).ready(function(){
$("ul li a").click(function(){
$("ul li a").removeClass('selected');
$(this).addClass('selected');
return false;
});
});
$('#menu li a').on('click', function(){
$('li a.current').removeClass('current');
$(this).addClass('current');
});
You need to add selected class in the clicked li element.
try like this:
$(document).ready(function(){
$("ul li a").click(function(){
$(".selected").removeClass('selected');
$(this).addClass('selected');
});
});
Actually you are redirecting when you are clicking in the li element. so jquery wil not be worked in this scenario.
it will work if you use one page application with out page reloading.
You can to do it by php like this:
// index.php
<?php
$page = isset($_REQUEST['p']) ? $_REQUEST['p'] : '';
switch($page) {
case 'skills' :
echo ' <ul>
<li>Home</li>
<li>Skills</li>
<li>About</li>
<li>Contact</li>
</ul>';
break;
case 'about' :
echo ' <ul>
<li><a href="index.php?p=home" >Home</a></li>
<li>Skills</li>
<li>About</li>
<li>Contact</li>
</ul>';
break;
case 'contact' :
echo ' <ul>
<li><a href="index.php?p=home" >Home</a></li>
<li>Skills</li>
<li>About</li>
<li>Contact</li>
</ul>';
break;
default:
echo ' <ul>
<li>Home</li>
<li>Skills</li>
<li>About</li>
<li>Contact</li>
</ul>';
}
hi i am using jquery ui sortable to sort my divs . i can get the div oder to save in the db , this is my code
<div style="margin:0 auto !important;">
<ul id="sortable1" class="connectedSortable">
<li id="one_1" class="ui-state-default"><div>Item 1</div></li>
<li id="one_2" class="ui-state-default"><div>Item 2</div></li>
<li id="one_3" class="ui-state-default"><div>Item 3</div></li>
<li id="one_4" class="ui-state-default"><div>Item 4</div></li>
<li id="one_5" class="ui-state-default"><div>Item 5</div></li>
</ul>
<ul id="sortable2" class="connectedSortable">
<li id="two_1" class="ui-state-highlight"><div>Item 1</div></li>
<li id="two_2" class="ui-state-highlight"><div>Item 2</div></li>
<li id="two_3" class="ui-state-highlight"><div>Item 3</div></li>
<li id="two_4" class="ui-state-highlight"><div>Item 4</div></li>
<li id="two_5" class="ui-state-highlight"><div>Item 5</div></li>
</ul>
</div>
<script type="text/javascript">
jQuery(function() {
var sortable1 = 'one_1,one_2,one_3,one_4,one_5';
var sortable2 = 'two_1,two_2,two_3,two_4,two_5';
jQuery( "#sortable1, #sortable2" ).sortable({
update: function(event, ui) {
var newOrder = jQuery(this).sortable('toArray').toString();
if(jQuery(this).attr('id')=="sortable1"){
sortable1 = newOrder;
}
else {
sortable2 = newOrder;
}
console.log(sortable1);
console.log(sortable2);
}
}).disableSelection();
});
</script>
i can save the sorted div order to DB correctly , but i have no idea how to populate the div's to correct order again . please help me . thanks in advance .
Instead of saving the sort order to the DB as the comma separated value 1,2,3,4,5, why not just save the 'sort column' e.g. #sortable1 such that when you are loading the divs you just pass this value to your js logic.
Example:
if you save the sort column name say #sortable1 or #sortableN in the DB then you end up with
var newOrder = jQuery(this).sortable('toArray').toString();
if(jQuery(this).attr('id')== "<% $your_php_variable %>"){
sortable1 = newOrder;
}
else {
sortable2 = newOrder;
}
Am not sure how you are passing the php variable to the UI that's what i've put as <% $your_php_variable %>. At some point in your php code you will have set $your_php_variable = '#sortableX';
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;
});
The below code works fine in Chrome, but doesn't work correctly in Firefox.
In Chrome:
Expanding the hide/show link shows the up arrow correctly when expanded and the down arrow when collapsed
In Firefox:
Expanding the hide/show link shows the up arrow correctly when expanded, but when collapsed it still shows the up arrow.
What am I doing wrong?
Thanks
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $divView = $('div.view');
var innerHeight = $divView.removeClass('view').height();
$divView.addClass('view');
$('div.slide').click(function() {
// Update the HTML in this element
var slideHtml = $(this).html();
// Switch between show/hide
if (slideHtml.localeCompare('Hide / Show <img src="images/arrow_up.png" />') < 0)
$(this).html('Hide / Show <img src="images/arrow_up.png" />');
else
$(this).html('Hide / Show <img src="images/arrow_down.png" />');
$('div.view').animate({
height: (($divView.height() == 90)? innerHeight : "90px")
}, 500);
return false;
});
});
</script>
<div class="view">
<ul>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
</ul>
</div>
<div class="slide">Hide / Show <img src="images/arrow_down.png" /></div>
You should use toggle() it is much simpler and it avoids you all this.
I made you an example here: http://jsfiddle.net/MVnbM/
HTML:
Click me
<div class="arrowUp">Up</div>
<div class="arrowDown">Down</div>
JS:
$('.arrowUp').hide();
$('a.clickMe').click(function() {
$('.arrowUp, .arrowDown').toggle();
});
Here's your code modified:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $divView = $('div.view');
var innerHeight = $divView.removeClass('view').height();
$divView.addClass('view');
$('.arrowUp').hide();
$('div.slide').click(function() {
$('.arrowUp, .arrowDown').toggle();
});
});
<div class="view">
<ul>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
<li>text here</li>
</ul>
</div>
<div class="slide">Hide / Show <img src="images/arrow_down.png" class="arrowUp" /><img src="images/arrow_down.png" class="arrowDown" /></div>
What about this variant using toggle and toggleClass
http://jsfiddle.net/347pg/