hide a child element on mouseout of parent DIV - AngularJs - javascript

HTML -
<div class="col-md-3" ng-repeat="idea in ideas">
<div class="col-md-12 ideaResult" ng-mouseleave="hideIcon()">
<a class="resultCover col-md-12" style="background-image:url(https://le-uploaded-image-bucket.s3.amazonaws.com/{{idea.coverImage}});"></a>
<div class="sharebtn icon-btn" ng-click="socialIcon = !socialIcon">
<span style="background-image:url('/images/idea/share-add.png');background-color:white" title="Share" class="iconContainer"></span>
</div>
<div class="share-fb share-icon" ng-show="socialIcon">
<span class="iconContainer" title="Share" style="background-image:url('/images/idea/fb-icon.png');background-color:white"></span>
</div>
<div class="share-tw share-icon" ng-show="socialIcon">
<span class="iconContainer" title="Share" style="background-image:url('/images/idea/twitter-icon.png');background-color:white"></span>
</div>
<div class="share-msg share-icon" ng-show="socialIcon">
<span class="iconContainer" title="Share" style="background-image:url('http://cdn.thegadgetflow.com/wp-content/themes/thegadgetflow4/images/email-icon.png');background-color:white"></span>
</div>
<div class="endorse-icon icon-btn">
<span style="background-image:url('/favicons/favicon-96x96.png');background-color:white" title="Endorse" class="iconContainer"></span>
</div>
<div class="resultIcon">
<span title="my goal" class="iconContainer" style="background-image:url(https://le-uploaded-image-bucket.s3.amazonaws.com/{{idea.goalIcon}});background-color:{{idea.backgroundColor}}">
</span>
</div>
<h2 class="resultName">{{idea.title}}</h2>
<div class="col-md-12 resultDescription"><p>{{idea.description | limitTo: 48}}{{idea.description.length > 48 ? '...' : ''}}Continue Reading</p></div>
</div>
</div>
Controller JS -
$scope.hideIcon = function(){
$scope.socialIcon = false;
};
Requirement -
I want to hide the DIVs with "share-icon" class when mouse pointer go out of the parent DIV(i.e. DIV with class ideaResult), but at the same time I click on the DIV with class name "shareBtn" which will result in toggling those three DIVs with "share-icon" class which is working fine.
Problem -
When the page is loaded, these three DIVs (ie. "share-icon" class) are already hidden which is fine but when I click on the DIV with class "shareBtn", these DIVs appear which is also fine, but when mouse pointer goes out of the parent DIV ("ideaResult"), these three DIVs continues to be appear which I don't want.
Can someone help me to solve this problem ? Thanks in advance
Here is the Mock Fiddle - https://jsfiddle.net/x2zzppoa/

The visibility on those 3 divs isn't related to the class "share-icon", but to $scope.socialIcon, whitch initialy is set to undefined, and after you click the upper div it is set to true, hence the visibility of your divs.
The solution for this code snippet is probably:
ng-mouseleave="socialIcon = false"
https://jsfiddle.net/ronapelbaum/x2zzppoa/1/

Related

Our dropdown is tabbable even when not expanded

We want our dropdown to be tabbable once expanded but non tabbable when not expanded. We have tried tabindex="-1" on the content in the expandable div but that made it non tabbable even once expanded. We have no idea on how to to solve this and would be grateful to any tips.
<div class="container">
<div class="accordionContent">
<div class="accordionItem">
<button class="itemHeader itemQuestion">
Text
<span class="itemIcon">
<i class="bx bx-chevron-down"></i>
</span>
</button>
<div class="itemContent">
<p class="itemAnswer">
<button>Example</button>
</p>
</div>
</div>
</div>
</div>
I dont know exactly what you want to do but If you want to showdiv.itemContent with click on the button.itemHeader you can do this :
-set display:none ;for div.itemContent
-use onclick event for button.itemHeader. And call this function :
function myfunction(){ document.getElementsByClassName[0]("itemContent").style.display=block; }

Show hide separate divs with jQuery

With my inexperience in jQuery, I'm finding the simplest tasks difficult.
What I attempt to do is show/hide certain messages when a certain icon is clicked. This is my HTML:
<div class="container">
<div class="row">
<div class ="col-md-2 pov_icon">
<div class="pov_icon_small" value="measure">
<i class="fa fa-clock-o"></i>
</div>
<div class="pov_title_small">
MEASURE
</div>
</div>
<div class ="col-md-2 pov_icon">
<div class="pov_icon_large" value="locate">
<i class="fa fa-map-marker"></i>
</div>
<div class="pov_title_large">
LOCATE
</div>
</div>
<div class ="col-md-2 pov_icon">
<div class="pov_icon_small" value="inform">
<i class="fa fa-commenting"></i>
</div>
<div class="pov_title_small">
INFORM
</div>
</div>
<div id="measure" style="display:none" class="pov_description">
<p> Message MESSAGE</p>
</div>
<div id="locate" class="pov_description">
<p> Message LOCATE</p>
</div>
<div id="inform" style="display:none" class="pov_description">
<p> Message INFORM</p>
</div>
</div>
</div>
My JavaScript code that changes the pov icon/title classes works and is currently here:
$('.pov_icon_small , .pov_icon_large').on('click', function () {
$('.pov_icon_large').not($(this)).removeClass('pov_icon_large').addClass('pov_icon_small');
$('.pov_title_large').not($(this).next('div[class^="pov_title_"]')).removeClass('pov_title_large').addClass('pov_title_small');
$(this).toggleClass("pov_icon_small").toggleClass("pov_icon_large");
$(this).next('div[class^="pov_title_"]').toggleClass("pov_title_small").toggleClass("pov_title_large");
});
What I aim to do, is display a certain message (e.g. Message Measure) when the a certain icon pov_icon_small value="measure" is clicked while keeping the others hidden. When the user clicks another icon; that respective message will be displayed and the others will be hidden :
$(document).ready(function(){
$('input[.pov_icon_small]').click(function(){
if($(this).attr("value")=="measure"){
$(".pov_description").not("#measure").hide();
$("#measure").show();
}
if($(this).attr("value")=="locate"){
$(".pov_description").not("#locate").hide();
$("#locate").show();
}
if($(this).attr("value")=="inform"){
$(".pov_description").not("#inform").hide();
$("#inform").show();
}
});
The message-linking JS code doesn't seem to work. Am I doing a small error here? Or should I be preparing the code in a completely different way?
Theres two issues, first your CSS selector input[.pov_icon_small] is not valid. The second is that you are attaching the click function to pov_icon_small which do not have enough height or width for a user to click. I've adjusted the HTML so this binds to the pov_title_small class instead.
You'll want to attach your click function to items have a value, then pass that value as the selector. For pov_title_small I've changed the attribute value to data-value, then the click function uses that to select the ID you want to display. Here is the code:
HTML:
<div class="container">
<div class="row">
<div class ="col-md-2 pov_icon">
<div class="pov_icon_small">
<i class="fa fa-clock-o"></i>
</div>
<div class="pov_title_small" data-value="measure">
MEASURE
</div>
</div>
<div class ="col-md-2 pov_icon">
<div class="pov_icon_large">
<i class="fa fa-map-marker"></i>
</div>
<div class="pov_title_large" data-value="locate">
LOCATE
</div>
</div>
<div class ="col-md-2 pov_icon">
<div class="pov_icon_small">
<i class="fa fa-commenting"></i>
</div>
<div class="pov_title_small" data-value="inform">
INFORM
</div>
</div>
<div id="measure" style="display:none" class="pov_description">
<p> Message MESSAGE</p>
</div>
<div id="locate" style="display: none;" class="pov_description">
<p> Message LOCATE</p>
</div>
<div id="inform" style="display:none" class="pov_description">
<p> Message INFORM</p>
</div>
Javascript:
$(document).ready(function(){
$('[data-value]').bind('click', function(){
$('.pov_description').hide();
$('#'+$(this).attr('data-value')).show();
});
});
You can see it working in this JS Fiddle: http://jsfiddle.net/h97fg75s/
1st : you just need to get a value and convert it to id ..
2nd: like #juvian mentioned $('input[.pov_icon_small]') is not a valid selector
3rd .pov_icon_small its a div not an input so you can use $('div.pov_icon_small') instead
4th: .pov_icon_small doesn't have any value attribute .. .pov_title_small and .pov_title_large those has the value attribute
$(document).ready(function(){
$('div.pov_title_small , div.pov_title_large').click(function(){
var ThisValue = $.trim($(this).attr('value'));
$(".pov_description").not("#"+ThisValue).hide();
$("#"+ThisValue).slideToggle()
});
});
Working Demo
if you need to control it from .pov_icon you have 2 ways
1st: put a value attribute in .pov_icon_small/large
2nd: you can use
$('div.pov_icon_small , div.pov_icon_large').click
and
var ThisValue = $.trim($(this).next('div[class^="pov_title_"]').attr('value'));

Change list-group-item from hidden to visible with JS

I have a list which contains of several items that are hidden.
In my JS i want a function that changes the items of this list so it becomes visible. I want each item to become visible if a certain event has happened. The event is working fine and can be considered as shakeCount= 6, to test it properly.
Here is my list:
<div class="container">
<div class="list-group">
<div id="s1">Shake1</div>
<div id="s2">Shake2</div>
<div id="s3">Shake3</div>
</div>
</div>
What i tried so far and didn't work:
function nR(){
if (shakeCount>5)
document.getElementbyId("s1").style.visibility ="visible";
}
Thanks in advance!
Have you tried using Toggle? I would recommend it but you may need to remove the "hidden" class from your elements and add in the style="display: none;" attribute to each in order to default them to hidden.
<div class="container">
<div class="list-group">
<div id="s1">Shake1</div>
<div id="s2">Shake2</div>
<div id="s3">Shake3</div>
</div>
</div>
function nR(){
if (shakeCount>5)
document.getElementbyId("s1").toggle();
}
First, you're using getElementbyId -- it should be getElementById (missing capital 'B').
Second, you've made the #shake links visibility:hidden, but you are targeting the wrapping div when you run your js.
var shakeCount = 6;
if (shakeCount>5)
document.getElementById("s1").style.visibility ="visible";
.hidden {visibility: hidden;}
<div class="container">
<div class="list-group">
<div id="s1" class="list-group-item hidden"><a href="#shake1" >Shake1</a></div>
<div id="s2" class="list-group-item hidden"><a href="#shake2" >Shake2</a></div>
<div id="s3" class="list-group-item hidden"><a href="#shake3" >Shake3</a></div>
</div>
</div>
The above code hides the wrapping div elements instead of the links so that they are shown when the js runs.

Add scroll left and right on a span in javascript

I have a emoticon palette which has the form like this :-
Categories div and then the emoticons div:-
<div class="emoticonbox" ng-if="showEmoticons">
<div class="categories_emo">
<span ng-repeat='cat in EmoticonCategoryPositions | limitTo: (EmoticonCategoryPositions.length-1)'>
<img ng-if="currentEmoticonCategory==$index" ng-src='{{emoticonDirPath}}tabs/emo_{{$index+1}}_tab_selected.png'
class="emoticon_tab" ng-click='setEmoticonCat($index)'/>
<img ng-if="currentEmoticonCategory!=$index" ng-src='{{emoticonDirPath}}tabs/emo_{{$index+1}}_tab.png'
class="emoticon_tab" ng-click='setEmoticonCat($index)'/>
</span>
<div class="categories--control">
<div class="rect rect--left" ng-click="moveleft()"></div>
<div class="rect rect--right" ng-click="moveright()"></div>
</div>
</div>
<div class="wrapEmoticons">
<img ng-repeat='emoticon in emoticonList[currentEmoticonCategory]' src='{{emoticonDirPath}}{{emoticon}}'
ng-click=' addEmoticon(EmoticonCategoryPositions[currentEmoticonCategory]+$index);main.messageClickFocus()' class="emoticons"/>
</div>
</div>
I want to add left and right arrow keys in the categories div so that I can browse categories by clicking the respective arrow.
I have added as you see above categories--control and with this javascript.
$scope.moveleft=function(){
var widthOneItem = parseInt($(".sticker_tab").first().css("width"))+parseInt($(".sticker_tab").first().css("margin-left"))+parseInt($(".sticker_tab").first().css("margin-right"))+parseInt($(".sticker_tab").first().css("padding-left"))+parseInt($(".sticker_tab").first().css("padding-right"));
console.log(widthOneItem);
$(".categories_sti").animate({scrollLeft: "-="+widthOneItem});
console.log("Moving Left");}
$scope.moveright=function(){
var widthOneItem = parseInt($(".sticker_tab").first().css("width"))+parseInt($(".sticker_tab").first().css("margin-left"))+parseInt($(".sticker_tab").first().css("margin-right"))+parseInt($(".col-md-3").first().css("padding-left"))+parseInt($(".col-md-3").first().css("padding-right"));
console.log(widthOneItem);
$(".categories_sti").animate({scrollLeft: "+="+widthOneItem});
console.log("Moving Right");}
Doesn't seem to work as required, no movement at all.

Toggle Javascript outside of parent

I have issues when trying to place an event to toggle a div using an element outside of the parent container.
I trying to target the same behavior from outside of the parent elements using a span tag.
Any help would be grateful.
HTML:
<div class='toggle_parent'>
<div class='toggleHolder'>
<span class='toggler'>Open</span>
<span class='toggler' style='display:none;'>Close</span>
</div>
<div class='toggled_content' style='display:none;width:100%;height:400px;'>
<h2>Hello This Is My Content Right Here</h2>
<span class='toggler btn btn-large'>Close</span>
</div>
</div>
<!-- I need this element to trigger from outside -->
<span class="toggler btn btn-large btn-info">Gain Early Access</span>
Javascript:
$('.toggler').live('click',function(){
/* $(this).parent().children().toggle(); //swaps the display:none between the two spans */
$(this).parent().parent().find('.toggled_content').slideToggle(); //swap the display of the main content with slide action
});
Amended your example to suit the purpose.
<div id="container">
<div>
<div>
<span class='open'>Open</span>
<span class='close' style='display:none;'>Close</span>
</div>
<div class='content' style='display:none;width:100%;height:400px;'>
<h2>Hello This Is My Content Right Here</h2>
<span class='close'>Close</span>
</div>
</div>
<!-- I need this element to trigger from outside -->
<span class="toggle">Gain Early Access</span>
</div>
$(".toggle").click( function( ) {
$(".content").slideToggle();
});
$(".open").click( function( ) {
$(".content").slideDown();
});
$(".close").click( function( ) {
$(".content").slideUp();
});
Just use a global parent div.
<div id="container">
<div class='toggle_parent'>
<div class='toggleHolder'>
<span class='toggler'>Open</span>
<span class='toggler' style='display:none;'>Close</span>
</div>
<div class='toggled_content' style='display:none;width:100%;height:400px;'>
<h2>Hello This Is My Content Right Here</h2>
<span class='toggler btn btn-large'>Close</span>
</div>
</div>
<!-- I need this element to trigger from outside -->
<span class="toggler btn btn-large btn-info">Gain Early Access</span>
</div>
And you can just do this :
var container = $('#container');
container.on('click', '.toggler', function() {
container.find('.toggleHolder .toggler').toggle();
container.find('.toggle_content').slideToggle();
});
By the way, if you use jQuery 1.7 or more, live is deprecated. See http://api.jquery.com/live/

Categories

Resources