function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
body{background:url(assets/bg.png)no-repeat;}
#drag1{margin-left:10px;}
#div1{background-color:#fff;border:2px dashed #a92928;width:193px;height:152px;float:left;margin-left:10px;}
<div class="drag_drop">
<img id="drag1" src="http://elets-winora.ru/sykkel/image_sykkel_18530_small.jpg" draggable="true" ondragstart="drag(event)">
<img id="drag1" src="http://www.charmingsharmapartments.com/_wp_generated/wp54f0f9a8_06.png" draggable="true" ondragstart="drag(event)">
<img id="drag1" src="http://www.aveac.org.uk/Shaun%20win.JPG" draggable="true" ondragstart="drag(event)">
<br>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
I have included only drag image to box how can play audio sound when drag to image to box given below following steps
Step 1: All drop area(with images like running etc.,) should be randomized
Step 2 : all audio should be randomized – for example if first audio after randomization is cycling then it has to play all 3 audios sequentially with 1 sec pause in between.
Step 3 : first drop area should be cycling as per random order of audio. If user has dropped wrong answer it has to go back to its original position.
Step 4 : if user don’t drop any thing and play audio again it will play again in same order. All audio will be played in sequential order from 1 to 4.
Step 5 : if user clicks reset it will randomize again audio and drop area again.
Related
I have a drag and drop html5 function which works fine :
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
So I set it on two elements lets say those two:
<div id="div1" id="drag1" draggable="true" ondragstart="drag(event)">
<h3> Monday </h3>
</div>
<div id="div1" id="drag1" draggable="true" ondragstart="drag(event)">
<h3> Tuesday </h3>
</div>
It works fine with the first element, but when I try to drag and drop the second one, it keeps droping the first one. I have also tested it on multiple items: only the first item drops when I drag any item ?
This is probably because you have 2 elements with the same ID: drag1. You should avoid giving your elements the same ID
I am building a schedule view, which is currently in a preliminary stage, where I add events and then I can rearrange them, either by dragging the event vertically upwards or downwards, or by resizing it vertically. For resizing, I'll click a button contained within the event and drag it up or down to resize the event. For a better view, please have a look at this opensource calendar.
I am currently facing an issue, in making my elements draggable. None of the drag events fire, although other (click, mouseover) do work. The following are snippets from what I've done till now. Please excuse me for my work, I'm still a little rusty at Angular.
*.component.html:
<table>
<tbody *ngFor="let item of FullHours; let i = index" >
<tr [ngSwitch]="returnItem(Doc)" [ngStyle]="{'background-color':returnItem(Doc) === ',' ? 'white' : 'yellow' }">
<td [style.height.px]="unitHeight" >
<div ondrop="drop($event)" ondragover="allowDrop($event)" *ngIf="hasEvent(i)" class="event-container" style="background-color: white;">
<div class="event" draggable="true" ondragstart="drag($event)">
<div style="width:100%; float:left" class="content">04:30PM -- 05:30PM</div>
<div style="width:100%; float:left" class="content">event {{i}}</div>
<button draggable="true" (dragover)="onDragOver($event)" (dragleave)="onDragLeave($event)" (drop)="onDrop($event)" class="eventbtn" style="position: absolute; left:0; right:0; bottom:0" >
=
</button>
</div>
</div>
<div *ngIf="!hasEvent(i)" (click)="createEvent(i)" class="event-container"></div>
</td>
</tr>
</tbody>
</table>
*.component.ts:
onDrop(event: any) {
alert('on-drop');
event.preventDefault();
event.stopPropagation();
// your code goes here after droping files or any
//try to change height
}
onDragOver(evt) {
alert('on-drag-over');
evt.preventDefault();
evt.stopPropagation();
}
onDragLeave(evt) {
alert('on-drag-leave');
evt.preventDefault();
evt.stopPropagation();
}
I've put in alerts on all binded functions, but none of them work. I did try this earlier with the whole event too but it still didn't work. I've created simple drag and drop divs wit JavaScript code but even those don't work in here. Do let me know if I need to provide anything else.
I'd be grateful for any guidance that can make my drag and drops work. Thanks in advance.
I want to play a movie once the mouse is hovering over it. Just like facebook.
<div class="col-sm-12">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="//www.youtube.com/embed/pQIXz-uhjIk">
</iframe>
</div>
</div>
The site is built with angularjs and html.
(Im quite new so please if possible also explain the solution not just paste code)
Br
Build up a solution "like" facebook in this plunker
To dynamically run the player, you'll have to integrate the ifram api.
You have to add this into your index.html
<script src="https://www.youtube.com/iframe_api"></script>
Then you need to handle the asynchronous load of their API (dunno why they did that) like this in your controller:
//i create a promise to wait for the YT.loaded to be true
var defered = $q.defer();
var promise = defered.promise;
//i launch this function until the YT.loaded is true
var interval = $interval(function(){
if(YT.loaded){
//if the YT api is loaded, i cancel the interval and resolve the promise
defered.resolve();
$interval.cancel(interval);
}
})
Now i can create a player when the YT api is ready :
var videoId = "pQIXz-uhjIk";
//when the API is ready
promise.then(function(){
//i create an Iframe player in the div with the "ytplayer" id
$scope.ytplayer = new YT.Player('ytplayer', {
height: '200',
width: '300',
videoId: videoId
}) ;
});
Now i have a full control on the player with the $scope.ytplayer object.
I prepare two function to start and pause a player :
$scope.startPlayer = function(player){
player.playVideo();
};
$scope.pausePlayer = function(player){
player.pauseVideo();
}
Now let see the HTML and the mouse tricks :
<div ng-show="ytplayer" ng-mouseenter="startPlayer(ytplayer)" ng-mouseleave="pausePlayer(ytplayer)" class="embed-responsive embed-responsive-16by9">
<div id="ytplayer"></div>
</div>
I show my div only if ytplayer is set. When i enter the div i run startPlayer() on the player ytplayer. When i leave the div i run pausePlayer() on the ytplayer.
The embed-responsive class is an inline-block to wrap the player
... And that's pretty much all.
Michelem's solutionis probably the best option and easiest option if you only have to start the player on mouseenter. But if you need more control on the player keep in mind my solution (even if it's a bit tricky).
Hope it helped.
This could be a solution you can play with:
JSFiddle
HTML:
<div ng-app="myApp" ng-controller="dummy">
<div class="col-sm-12">
<div class="embed-responsive embed-responsive-16by9">
<div ng-hide="url" ng-mouseenter="url = 'http:////www.youtube.com/embed/pQIXz-uhjIk?autoplay=1'">OVERME</div>
<iframe ng-show="url" class="embed-responsive-item" ng-src="{{trustSrc(url)}}"></iframe>
</div>
</div>
</div>
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$sce', function ($scope, $sce) {
$scope.trustSrc = function (src) {
return $sce.trustAsResourceUrl(src);
}
}]);
I have a HTML5 drag and drop function. You can drag an item from div1 to div2.
What I want to do is for every item dropped into div2, automatically give it a list number.
At the minute the JS code for adding the text to div2 looks like this:
function drop(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild( document.getElementById(data));
}
Above drops the element into div2. Below describes the drag function.
function drag(ev) {
ev.dataTransfer.setData("Text",ev.target.id);
}
The html looks like this:
<div id="div1" ondrop="drop(event)">
<div id="title" draggable="true" ondragstart="drag(event)" style="font-family:Metacopy">Text to be Dragged</div>
</div>
<div id="div2" ondrop="drop(event)"></div>
I'd be grateful for any help. Sorry if the answer is glaringly obvious, I'm kind of new to this.
I am using this code
<div onclick="thevid=document.getElementById('thevideo');
thevid.style.display='block';
this.style.display='none'">
<img src="../img/film.jpg" style="cursor:pointer" />
</div>
<div id="thevideo" style="display:none">
<iframe width="600"
height="335"
src="https://www.youtube.com/embed/MZ-NmMMTyTU?&rel=0&theme=light&showinfo=0&disablekb=1&hd=1&autohide=1&color=white&autoplay=1"
frameborder="0"
allowfullscreen>
</iframe></div>
</div>
To embed a YouTube video on my site, and it is working fine in Firefox. But in Chrome the video starts playing, behind the image i have placed on top.
Any ideas how to fix this?
I just made one YouTube handler, with Javascript API.
HTML code:
<b id="youbox" class="youbox youbox-left">
<div id="player"></div> <!--player will loads here-->
</b>
<div id="youtube-select" class="youtube-select clearfix">
<ul>
<!-- use this part as a dynamic block, so you can multiply this -->
<li class="playanothervideo {ACTIVE}" rel="{YOUTUBE VIDEO ID}">
<h1>{TITLE OF VIDEO}</h1>
</li>
<!-- end of dynamic block. important: at the dom ready you have to make one li active, because that will be the first loaded video -->
</ul>
</div>
The javascript
if (($("#youbox").size() > 0)) // if you have youbox, which means you want a youtube player
{
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player; // insert youtube player api to the html source, and make a player instance
function onYouTubePlayerAPIReady() // on youtube player api loaded
{
player = new YT.Player('player', {
height: '350', // height of player
playerVars: { 'color': 'white', 'theme': 'light', 'modestbranding': 1, 'rel':0, 'showsearch':0, 'showinfo': 0, 'iv_load_policy': 3, 'hd': 1, 'controls':1}, // personalize players lookout (this is white instead of red)
width: '629', // width of player
videoId: $("#youtube-select li.active").attr("rel"), // aye, this is the first video id's getter
events:
{
'onReady': onPlayerReady, // the easiest event handling, calls onplayerready fn
}
});
}
function playAnotherVideo(id) // play another video event handler
{
if (player.getPlayerState() == 1) // if video is playing
{
console.log("playerstate ok")
player.stopVideo(); // stops video
player.loadVideoById(id); // load other
player.playVideo(); // starts other
}
else
{
player.cueVideoById(id); // if not playing just loads the other video's thumbnail
}
}
function onPlayerReady(event)
{
event.target.setPlaybackQuality("hd720"); // setting 720p resolution by default (it's not tested yet, sorry)
}
}
and from an other js, but can apply to the first:
$(".playanothervideo").live("click", function(){
playAnotherVideo($(this).attr("rel"));
pickMe($(this), "active");
});
function pickMe(e, c) {
e.siblings(e[0].tagName).removeClass(c);
e.addClass(c);
}
which select the videos and handle their active class.
Good luck with Youtubein. :)
For more informations check: https://developers.google.com/youtube/js_api_reference