Antworten auf deine Fragen:
Neues Thema erstellen

HMTL5 Video-Element manipulieren

johnreinert

Nicht mehr ganz neu hier

Ich habe auf meiner HP das Video-Element mittels dem opacity-Element manipuliert so das es erst zu 100% sichtbar wird wenn die Maus dieses Element berührt. Nur habe ich da das Problem das wenn die Maus das Element verlässt, es wieder durchsichtig wird... das ist eigentlich so gewohlt, nur geschieht es auch wenn das Video abgespielt wird.

Wie kann ich das so manipulieren das es beim Abspielen des Videos den Hover-Status annimmt, also zu 100% sichtbar wird?
 

Panzerkrokette

Nicht mehr ganz neu hier

AW: HMTL5 Video-Element manipulieren

Hi,
das wird so nicht funktionieren. Du manipulierst ja den Container / Viewer / Player Background - NICHT das eigentliche Video. MP4 und OGG kann keine Transparenzen darstellen - bzw. nur mit einem Trick: http://bit.ly/dehvMd
Sobald also das Video läuft ist Opacity des Bereichs durch das Videoelement wieder 100%.
Besser also ein Freeze Frame des Videos als jpg Thumbnail per MouseOver manipulieren, dann per Klick das Video starten (vllt in einer Shadowbox?).
Cheers
PK
 

mindraper

me[code].Java(Script)

AW: HMTL5 Video-Element manipulieren

hi,

kannst du bitte (zumindest ausschnittweise) dein markup + deine stylesheets posten? für den effekt, den du erreichen möchtest, musst du deinem <video>-element bzw. besser einem umliegenden <div>-container eine zweite klasse verpassen, sobald das video abgespielt wird. eine reine css basierte lösung kann ich mir auf die schnelle nicht vorstellen, da wirst du wohl javascript brauchen.

beispielsweise so was:

JavaScript
PHP:
(function (window) {

    /** GLOBAL HELPERS
     *  ----------
     */

    /** used to delete circular references which lead to memory leaks
     *  ----------
     *  @param references {Objects}: one or more references to nullify
     */
    var free = function (references) {
        var i = 0,
            l;

        for (l = arguments.length; i < l; i += 1) {
            arguments[i] = null;
        }
    };

    /** checks if the given node owns the given class
     *  ----------
     *  @param node {DOMNode}: the node to check
     *  @param clnm {String}: the class to be checked
     *  @returns {Boolean}: true if the given node owns the class, otherwise false
     */
    var hasClass = function (node, clnm) {
        var regex = new RegExp('\\s+?' + clnm + '\\b');
        return regex.test(node.className);
    };

    /** adds the given class to the given node if the node does not own the class,
     *      otherwise it removes the given class
     *  ----------
     *  @param node {DOMNode}: the node
     *  @param clnm {String}: the class to add/remove
     *  @returns {Boolean}: always true
     */
    var handleClass = function (node, clnm) {
        var regex,
            clnms;

        if (hasClass(node, clnm)) {
            regex = new RegExp('\\s+?' + clnm + '\\b', 'g');
            node.className = node.className.replace(regex, '');

            free(regex);
            return true;
        }

        regex = /\s+/;
        clnms = node.className.split(regex);
        clnms[clnms.length] = clnm;
        node.className = clnms.join(' ');

        free(regex, clnms);
        return true;
    };

    /** binds ('hitches') a function to be executed in the given context, e. g.: sets
     *      the this keyword to refer to the given context
     *  ----------
     *  @param handler {Function}: function to hitch
     *  @param context {Object}: the new scope for handler
     *  @returns {Function}: a new function with bound ('hitched') scope
     */
    var hitch = function (handler, context) {
        return function () {
            var args = Array.prototype.slice.call(arguments);
            handler.apply(context, args);
        };
    };

    /** same as hitch, but designed for usage with eventListeners
     *  ----------
     *  @param handler {Function}: function to hitch
     *  @param context {Object}: the new scope for handler
     *  @returns {Function}: a new function with bound ('hitched') scope
     */
    hitch.event = function (handler, context) {
        return function (event) {
            var args = Array.prototype.slice.call(arguments, 1);
            args.unshift(fixEvents(event, context));
            handler.apply(context, args);
        };
    };

    /** wipes out some differences between Microsofts implementation of the event object
     *      and the standard (W3C) event object
     *  ----------
     *  @param event {Event Object}: generic event object
     *  @param context {Object}: context to be set as event.target
     *  @returns {Event Object}: a somewhat 'unified' generic event object
     */
    var fixEvents = function (event, context) {
        var e = event || window.event;
        if (typeof e.target === 'undefined') {
            e.target = e.srcElement || context;
        }

        if (typeof e.preventDefault === 'undefined') {
            e.preventDefault = function () {e.returnValue = false;};
        }

        if (typeof e.stopPropagation === 'undefined') {
            e.stopPropagation = function () {e.cancelBubble = true;};
        }

        return e;
    };

    /** adds eventListeners to the given node. the given handler will be executed in the scope
     *      of context or, if context is omitted, in the scope of the given node
     *  ----------
     *  @param node {DOMNode}: the node to add the listener to
     *  @param type {String}: the type of event to listen to (e. g.: 'click')
     *  @param handler {Function}: function to executed if the given eventtype occurs
     *  @param context {Object}: the context (scope) for the handler
     *  @param propagate {Boolean}: true the event should propagate (rarely needed)
     *  @returns {Boolean}: true on success, false if no listener has been added
     */
    var addListener = function (node, type, handler, context, propagate) {
        var bound = hitch.event(handler, (context || node));

        if (typeof node.addEventListener === 'function') {
            node.addEventListener(type, bound, (propagate || false));

            free(bound);
            return true;
        } else if (typeof node.attachEvent === 'function') {
            node.attachEvent('on' + type, bound);

            free(bound);
            return true;
        }

        return false;
    };

    /** PLUGIN
     *  ----------
     */

    /** plugin constructor function, awaits a nodelist/array/nodecollection as argument
     *  ----------
     *  @param nodelist {DOMCollection|Array}: a collection or array of all <video>-elements
     *  @returns {Object}: the new created Videofader instance
     */
    var Videofader = function (nodeList) {
        var videoNodes = [],
            node,
            i = 0;

        if ((typeof nodeList !== 'object') &&
            (typeof nodeList.length !== 'number') ||
            (nodeList.length < 1)
            ) {
                for (; node = nodeList[i]; i += 1) {
                    if ((typeof node === 'object') &&
                        (typeof node.nodeType === 'number') &&
                        (typeof node.nodeName === 'string') &&
                        (node.nodeName.toLowerCase() === 'video')) {
                            videoNodes[i] = node;
                    }
                }
        }

        this.nodes = videoNodes;
        this.length = videoNodes.length;

        free(videoNodes, node);
        return this.wrap();
    };

    Videofader.prototype = {
     constructor: Videofader
    };

    /** wraps every given <video>-element into its very own <div>-container
     *  ----------
     *  @returns {Object}: same as constructor [[INTERNAL_USE]]
     */
    Videofader.prototype.wrap = function () {
        var nodes = this.nodes.slice(),
            sandbox,
            node,
            tmp,
            i = 0;

        this.nodes = [];

        for (; node = nodes[i]; i += 1) {
            tmp = node.*****Node(true);

            sandbox = document.createElement('div');
            sandbox.appendChild(tmp);

            this.nodes[i] = sandbox;
            node.parentNode.replaceChild(sandbox, node);
        }

        free(nodes, sandbox, node, tmp);
        return this;
    };

    /** adds eventlisteners to the instances <div>-wrappers
     *  ----------
     *  @param type {String}: the type of event that should be listened to
     *  @returns {Object}: same as constructor [[INTERNAL_USE]]
     */
    Videofader.prototype.listenTo = function (type) {
        var node,
            i = 0;

        for (; node = this.nodes[i]; i += 1) {
            addListener(node, type, this.onEventHandle);
        }

        free(node);
        return this;
    };

    Videofader.prototype.onEventHandle = function () {
        handleClass(this, 'protects-opacity');
    };

    window.Videofader = Videofader;

})(this);

benutzt wird das ganze so:
PHP:
window.onload = function () {
    /* get all <video>-elements */
    var videoElems = document.getElementsByTagName('video');
    
    /* register the elements to a new Videofader */
    var videoFader = new Videofader(videoElems);

    /* let the Videofader listen to click events */
    videoFader.listenTo('click');
};

falls du nur bei bestimmten videos das ein- und ausblenden abschalten möchtest, sobald der besucher sie angeklickt hat, solltest du diese elemente mit document.querySelectorAll(*CSS_SELECTOR_STRING*) auswählen.
PHP:
window.onload = function () {
    /* get all elements with class .videofader */
    var videoElems = document.querySelectorAll('.videofader');
    
    /* register the elements to a new Videofader */
    var videoFader = new Videofader(videoElems);

    /* let the Videofader listen to click events */
    videoFader.listenTo('click');
};

jQuery

das Videofader plugin ist zu 100% kompatibel mit jQuery. allerdings ändert sich die benutzung leicht:
PHP:
/* shortform of $(document).ready(function () {}); */
$(function () {
    /* get all elements with class .videofader */
    var videoElems = $('.videofader').toArray();
    
    /* register the elements to a new Videofader and
     *     let the Videofader listen to click events
     */
    var videoFader = new Videofader(videoElems);
    videoFader.listenTo('click');
});

CSS
du musst deine stylesheets noch um folgende klasse erweitern, damit das plugin funktionieren kann (bzw. damit du die transparenz "fixieren" kannst, solange das video läuft:

Code:
.protects-opacity {
    opacity: 1 !important;
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100) !important;
}

hoffe das hilft!
 
Zuletzt bearbeitet:
Bilder bitte hier hochladen und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Antworten auf deine Fragen:
Neues Thema erstellen

Willkommen auf PSD-Tutorials.de

In unseren Foren vernetzt du dich mit anderen Personen, um dich rund um die Themen Fotografie, Grafik, Gestaltung, Bildbearbeitung und 3D auszutauschen. Außerdem schalten wir für dich regelmäßig kostenlose Inhalte frei. Liebe Grüße senden dir die PSD-Gründer Stefan und Matthias Petri aus Waren an der Müritz. Hier erfährst du mehr über uns.

Stefan und Matthias Petri von PSD-Tutorials.de

Nächster neuer Gratisinhalt

03
Stunden
:
:
25
Minuten
:
:
19
Sekunden

Neueste Themen & Antworten

Flatrate für Tutorials, Assets, Vorlagen

Zurzeit aktive Besucher

Statistik des Forums

Themen
118.565
Beiträge
1.538.066
Mitglieder
67.488
Neuestes Mitglied
Andrew56524
Oben