I've made it work by these codes for an addtional title (a new div inside fancybox):
beforeShow: function(){
this.title=$(this.element).data('caption');
this.title2="<div class='photo_exif'>"+$(this.element).data('exif')+"</div>";
$(this.title2)
.bind("contextmenu", function (e) {
return false; /* Disables right click */
})
.prependTo( $.fancybox.inner );
}
and the html is :
<a href='PhotoURL' class='fancybox' data-fancybox-group='gallery' data-caption='PhotoTitle' data-exif='photoTitle2'>pic</a>
now i want this div (div.photo_exif) hover to show or hide, so i added these codes:
afterShow:function() {
$("#fancybox-wrap").hover(function() {
$(".photo_exif").show();
}, function() {
$(".photo_exif").hide();
});
}
but it doesnt work. The div is always show on fancybox. My css is :
.photo_exif {
position: absolute;
bottom: 0;
left: 0;
color: #fff;
width:100%;
height:30px;
background: #000;
background: rgba(0, 0, 0, .8);
}
and my whole fancybox code (with ie6 crack) is :
$('.fancybox').fancybox({
fitToView: false,
mouseWheel: false,
beforeShow: function(){
this.title=$(this.element).data('caption');
this.title2="<div class='photo_exif'>"+$(this.element).data('exif')+"</div>";
$(this.title2)
.bind("contextmenu", function (e) {
return false; /* Disables right click */
})
.prependTo( $.fancybox.inner );
},
afterShow: function(){
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 6) {
$("div#fancybox-buttons").css("top", $("html").scrollTop());
$(window).scroll(function () {
$("div#fancybox-buttons").css("top", $("html").scrollTop());
});
}
$("#fancybox-wrap").hover(function() {
$(".photo_exif").show();
}, function() {
$(".photo_exif").hide();
});
}
});
Is there anything wrong?
This one was easy. This line of your code :
$("#fancybox-wrap").hover(function() {
... should be :
$(".fancybox-wrap").hover(function() {
The fancybox selector is a class not an ID
Related
This question already has answers here:
Why do I get different results with "=" vs. "===" in javascript with Conditional (Ternary) Operators?
(4 answers)
Closed 1 year ago.
first post, im trying to make a slide menu of some kind, and although it works clicking once and letting the menu options come forth. clicking again results in redoing the opening animation, instead of subtracting them back to their first location.
let menuopen = false;
$(document).ready(function(e) {
$("#menu_button").on('click',function(e) {
if (menuopen == false) {
$("#menu_button").css({"left":"500px"}).animate({left: '450px'})
$("#menu_select").css({"left":"500px"}).animate({left: '750px'});
$("#menu_select_two").css({"left":"500px"}).animate({left: '1050px'});
menuopen == true;
}
else if (menuopen == true) {
$("#menu_button").css({"left":"450px"}).animate({left: '500px'})
$("#menu_select").css({"left":"750px"}).animate({left: '500px'});
$("#menu_select_two").css({"left":"1050px"}).animate({left: '500px'});
menuopen == false
}
});
});
You are not assigning
menuopen == true;
should be
menuopen = true;
In any case: Why else if, just use else?
Try this - it saves the state in the button
You COULD use a ternary but that would be messy in this case
$(function(e) {
$("#menu_button").on('click',function(e) {
const menuopen = !!$(this).data("open"); // force boolean
if (menuopen) {
$("#menu_button").css({"left":"450px"}).animate({left: '500px'})
$("#menu_select").css({"left":"750px"}).animate({left: '500px'});
$("#menu_select_two").css({"left":"1050px"}).animate({left: '500px'});
}
else {
$("#menu_button").css({"left":"500px"}).animate({left: '450px'})
$("#menu_select").css({"left":"500px"}).animate({left: '750px'});
$("#menu_select_two").css({"left":"500px"}).animate({left: '1050px'});
}
$(this).data("open",!menuopen)
});
});
Perhaps
const butOpen = { "left": "450px" },
butClosed = { "left": "500px" },
selectOpen = { "left": "750px" },
selectClosed = { "left": "500px" },
select2Open = { "left": "1050px" },
select2Closed = { "left": "500px" }
$(function(e) {
$("#menu_button").on('click', function(e) {
const menuopen = !!$(this).data("open"); // force boolean
$("#menu_button").css(menuopen ? butOpen : butClosed).animate(menuopen ? butClosed : butOpen)
$("#menu_select").css(menuopen ? selectOpen : butClosed).animate(menuopen ? selectClosed : selectOpen)
$("#menu_select_two").css(menuopen ? select2Open : select2Closed).animate(menuopen ? select2Closed : select2Open)
$(this).data("open", !menuopen)
});
});
Or use a class and toggle it:
window.addEventListener("load", function(e) {
const wrapper = document.querySelector(".wrapper");
document.getElementById("menu").addEventListener("click", function(e) {
wrapper.classList.toggle("open");
this.textContent = wrapper.classList.contains("open") ? "Close" : "Open";
})
})
.wrapper {
position: relative;
overflow: hidden;
width: 100px;
height: 100px;
border: 1px solid black;
}
#slide {
position: absolute;
left: -100px;
width: 100px;
height: 100px;
background: blue;
transition: 1s;
}
.wrapper.open #slide {
transition: 1s;
left: 0;
}
<button id="menu" type="button">Open</button>
<div class="wrapper">
<img id="slide" src="https://lorempixel.com/output/cats-q-c-100-100-4.jpg" />
</div>
I am trying to create a directive in AngularJS which acts as Input and Select box together. Just like when you type in search textbox a dropdown list popups for assisting user to select. The selection is working fine via mouseclick, but I want my user to use arrow keys to move up and down and select on enter as well. Below is my HTML , CSS and Javascript code. Your quick assistance in this regard will be appreciated.
/*******CSS Code******/
.input-dropdown {
position: relative;
display: inline-block;
}
.input-dropdown .dropdown {
display: none;
position: absolute;
top: 100%;
left: 0;
width: 100%;
margin-top: 2px;
background: #EEE;
}
.input-dropdown .dropdown div {
cursor: pointer;
padding: 2px 5px;
}
.input-dropdown input:focus + .dropdown {
display: block;
}
/*******AngularJS Code*****************/
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.values = ['Chrome', 'Firefox', 'IE'];
$scope.pick = function (value) {
console.log('Picked', value)
};
});
app.directive('inputDropdown', function ($compile) {
var template =
'<input ng-model="ngModel">' +
'<div class="dropdown">' +
'<div ng-repeat="value in list | filter: ngModel">' +
'<div ng-mousedown="select($event, value)">{{value}}</div>' +
'</div>' +
'</div>';
return {
restrict: 'EA',
scope: {
ngModel: '=',
list: '=',
onSelect: '&'
},
template: template,
link: function (scope, element, attrs) {
element.addClass('input-dropdown');
scope.select = function (e, value) {
scope.ngModel = value;
scope.onSelect({ $event: e, value: value });
};
}
};
});
HTML Code:
<html ng-app="myApp">
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body ng-controller="MainCtrl">
<input-dropdown ng-model="preference" list="values" on-select="pick(value)"></input-dropdown> {{preference}}
</body>
</html>
I have two button + and - . When I click on + button I am adding one div in parent div and want to show tooltip on that div when I click again on + button then I am adding again one div and want to show tooltip on second div only. It's same for upto 7 div.
Currently I am doing same but when I add more than one div tooltip will not hide for previous button and will still there. So at end I am seeing all 7 tooltip but I supposed to see last div tooltip only.
I tried to hide it after some delay but even it's not working.
Here is my code.
function init(){
for(var divCount = 1; divCount <= fanSpeed; divCount++){
$('#temperature_bar').append('<div style="float:left" data-tooltip-id="'+divCount+'" id="speed_"'+divCount +'" class="trigger climate-fan-bar" onclick="\buttonTempraturePressed(this.id)\" title="<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="images/fan_speed_bg_center_popup.png" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + divCount + '</span></div></div></div></div>' );
showTooltips("speed_"+divCount);
}
}
function showTooltips(clicked_id){
//show
$(clicked_id).on('click', '.trigger', function () {
$(this).addClass("on");
$(this).tooltip({
hide: { effect: "flip", duration: 1000 },
items: '.trigger.on',
position: {
my: "top",
at: "top",
collision: "flip"
}
});
$(this).trigger('mouseenter');
});
/*$(clicked_id).on('click', '.trigger.on', function () {
$(this).tooltip('close');
$(this).removeClass("on");
});*/
//prevent mouseout and other related events from firing their handlers
$(".trigger").on('mouseout', function (e) {
e.stopImmediatePropagation();
});
}
Here is an possible solution. Making use of the items and content options, you can adjust the content instead of trying to pass it via title attribute.
Working Example: https://jsfiddle.net/Twisty/cfd6z8db/
HTML
<div style="padding:20px; display: block;">
<div id="temperature_bar">
</div>
</div>
<div style="padding:20px; display: block;">
<label>Speed</label>
<button id="decSpeed" title="Decrease">-</button>
<button id="incSpeed" title="Increase">+</button>
</div>
CSS
.item {
border-style: solid;
border-width: 1px 1px 1px 0;
border-color: #ccc;
padding: .25em .5em;
cursor: pointer;
}
.item:nth-child(1) {
border-left-width: 1px;
}
.row-thumbnail .caption {
width: 100%;
text-align: center;
}
jQuery
function showToolTips(obj) {
if (obj.hasClass("on")) {
// Hide ToolTip
obj.removeClass("on");
obj.tooltip("close");
} else {
// Show ToolTip
obj.addClass("on");
obj.tooltip("open");
}
}
function addItem() {
var divCount = $(".item").length + 1;
if (divCount == 8) {
return false;
}
var img = "https://dummyimage.com/50x50/000000/fff";
var item = $("<div>", {
id: "speed-" + divCount,
class: "trigger item",
"data-tip-content": img + "|" + divCount,
"data-tip-id": divCount,
})
.css("float", "left");
item.html(divCount);
item.tooltip({
disabled: true,
hide: {
effect: "flip",
duration: 1000
},
position: {
my: "center bottom+5",
at: "center top",
collision: "flip"
},
items: "[data-tip-content]",
content: '<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="' + item.data("tip-content").split("|")[0] + '" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + item.data("tip-content").split("|")[1] + '</span></div></div>'
});
$('#temperature_bar').append(item);
}
// Make Items
function init() {
var c = 5;
var divCount = 1;
for (divCount; divCount <= c; divCount++) {
var item = $("<div>", {
id: "speed-" + divCount,
class: "trigger item",
"data-tip-content": "https://dummyimage.com/50x50/000000/fff" + "|" + divCount,
"data-tip-id": divCount,
})
.css("float", "left");
item.html(divCount);
item.tooltip({
disabled: true,
hide: {
effect: "flip",
duration: 1000
},
position: {
my: "center bottom+5",
at: "center top",
collision: "flip"
},
items: "[data-tip-content]",
content: '<div class="row row-thumbnail" id="box-search"><div class="thumbnail text-center"><img width="50" height="50" src="' + item.data("tip-content").split("|")[0] + '" class="img-responsive"><div class="caption"><span class="tooltip-text-size">' + item.data("tip-content").split("|")[1] + '</span></div></div>'
});
$('#temperature_bar').append(item);
}
}
$(function() {
init();
$(".trigger").on('mouseout', function(e) {
if ($(this).hasClass("on")) {
$(this).removeClass("on");
$(this).tooltip("close");
}
});
$("#temperature_bar").on("click", ".trigger", function() {
console.log("Click Triggered. Executing 'showToolTips()'.");
showToolTips($(this));
});
$("#decSpeed").click(function() {
$("#temperature_bar .item").last().remove();
});
$("#incSpeed").click(addItem);
});
When using a position like { my: "top", at: "top", collision: "flip" }, this caused some type of weird loading issue. I used a different position and it seemed to clear the issue.
You post did not give a very strong example, so I created some example buttons. the disable option was also helpful, this ensured that they didn't display on mouseover events. It also allows us to control the open and close.
I packaged all the content items into a data attribute. I separated it with a pipe (|) so that it can all be one spot, but easily worked with later.
Click a button, and the tip appears. Click it again, and it hides. Same if you move the mouse away.
If you need more info, please update your post with a better example.
I would simply execute
$(".ui-tooltip-content").hide();
to:
function showTooltips(clicked_id){
$(".ui-tooltip-content").hide(); // Clean up prior tips
//show
$(clicked_id).on('click', '.trigger', function () {
$(this).addClass("on");
$(this).tooltip({
...
hth
I have this code for making a nav bar. I am trying to add image buttons with text below them. The problem is that the images can be of different sizes and thus they are not centered properly in the output.
Also, the title for all images must come at same level but its not the case.
ul.nav-icon {
list-style: none;
display: block;
margin: auto;
width: 800px;
}
ul.nav-icon li {
float: left;
}
ul.nav-icon a {
display: inline-block;
text-decoration: none;
}
ul.nav-icon a:hover {
background: #4095A6;
}
ul.nav-icon img {
margin: 0px 0px 0px 0px;
padding-top: 16px;
padding-left: 30px;
}
.img-box {
width: 160px;
height: 138px;
}
h6 {
color: white;
text-align: center;
}
<ul class="nav-icon">
<li>
<a href="#" class="img-box">
<img src="http://imgur.com/Et4vXHk.png">
<h6>Families</h6>
</a>
</li>
<li>
<a href="#" class="img-box">
<img src="http://i.imgur.com/lubEbTP.png">
<h6>Families</h6>
</a>
</li>
<li>
<a href="#" class="img-box">
<img src="http://i.imgur.com/lubEbTP.png">
<h6>Families</h6>
</a>
</li>
</ul>
Here's a way to deal with your problem: https://github.com/smohadjer/sameHeight
Here's the .js file you'll need to include in your html. It's better if it's an external file. For any confusion, this file can also be found in the link above with both minified/unminified versions.
;(function ($, window, document, undefined) {
'use strict';
var pluginName = 'sameHeight',
defaults = {
oneHeightForAll: false,
useCSSHeight: false
};
//private method
var getHeightOfTallest = function(elms) {
var height = 0;
$.each(elms, function() {
var _h = $(this).outerHeight();
if (_h > height) {
height = _h;
}
});
return height;
};
// The actual plugin constructor
function Plugin(element, options) {
this.$element = $(element);
this.options = $.extend({}, defaults, options);
this.init();
}
// methods
var methods = {
init: function() {
var self = this;
self.index = 0;
self.$elms = self.$element.children();
self.cssProperty = self.options.useCSSHeight ? 'height' : 'min-height';
$(window).on('resize.' + pluginName, function() {
//remove previously set height or min-height
self.$elms.css(self.cssProperty, '');
initSameHeight();
});
//use setTimeout to make sure any code in stack is executed before
//calculating height
setTimeout(function() {
initSameHeight();
}, 0);
function initSameHeight() {
//if there are adjacent elements
if (self.getRow(0).length > 1) {
self.setMinHeight(0);
if (self.options.callback) {
self.options.callback();
}
}
}
},
setMinHeight: function(index){
var self = this;
var row = self.options.oneHeightForAll ? self.$elms : self.getRow(index);
var height = getHeightOfTallest(row);
$.each(row, function() {
$(this).css(self.cssProperty, height);
});
if (!self.options.oneHeightForAll && self.index < self.$elms.length - 1) {
self.setMinHeight(self.index);
}
},
getRow: function(index) {
var self = this;
var row = [];
var $first = self.$elms.eq(index);
var top = $first.position().top;
row.push($first);
self.$elms.slice(index + 1).each(function() {
var $elm = $(this);
if ($elm.position().top === top) {
row.push($elm);
self.index = $elm.index();
} else {
self.index = $elm.index();
return false;
}
});
return row;
},
destroy: function() {
var self = this;
//remove event handlers
$(window).off('resize.' + pluginName);
//remove dom changes
self.$elms.css(self.cssProperty, '');
self.$element.removeData('plugin_' + pluginName);
}
};
// build
$.extend(Plugin.prototype, methods);
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function(options) {
this.each(function() {
if(!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
}
});
return this;
};
})(jQuery, window, document);
After you include the above .js file, add this script to your current page:
$('.img-box').sameHeight();
This should make all of your boxes with image/text be the same size height wise.
Next in order to make sure the text is always at a certain point within your img-box, add some css inline, or make a class with the css as
h6 {
bottom:10px;
}
The amount of pixels can be anything you'd like it to be. To explain, the text will now always be 10 pixels from the bottom of the img-box.
Either this, or just make the images the background image for the container and set them all to predetermined sizes.
$(document).ready(function () {
$("img#ucar").load(function () {
$(this)
.animate({ opacity: 1 / 2 }, 600)
.animate({ top: "616px" }, 300)
.animate({ opacity: 1 }, 0);
return false;
});
});
.ism {
top: -400px;
width: 225px;
height: 345px;
margin: 0;
padding: 0;
position:absolute;
}
#ucar {
position: relative;
}
<div class="ism">
<img id="ucar" src="images/img01.png" />
</div>
This code is working chrome but not working IE 11. I looked at other questions only answer I could not find on the site.
This happens mainly to cached images that get loaded (due to the caching) before the script has time to execute.
Add a check to see if the image is already loaded and trigger the script..
$(document).ready(function () {
$("img#ucar").load(function () {
$(this)
.animate({ opacity: 1 / 2 }, 600)
.animate({ top: "616px" }, 300)
.animate({ opacity: 1 }, 0);
return false;
}).each(function(){
if (this.complete){
$(this).trigger('load');
}
});
});
Demo at http://jsfiddle.net/gaby/k7vz0dgv/
It seems that the .load() function is not triggered in IE for some reason.
You could manually trigger the event by telling the image to load an empty string "" so once its done, the callback function will execute:
$(document).ready(function () {
// have a look at the load function
$("img#ucar").load("",function () {
$(this).animate({
opacity: 1 / 2
}, 600).animate({
top: "616px"
}, 300).animate({
opacity: 1
}, 0);
return false;
});
});
Fiddle Example